Gameover screen problems

Yes. [import]uid: 128294 topic_id: 33981 reply_id: 135103[/import]

I still do think you need to look into the displayGroup management in your game. I can not see that the hudGroup is ever created in the first place.

I am not shure how appropriate it is to mix director and storyboard in the same project. I would pick one and stick to it, since they both removes objects in each scene (I guess).

(Sorry if I sound like a looping record…) [import]uid: 25729 topic_id: 33981 reply_id: 135405[/import]

First thing I would do is put a print statement in the callGameOver function to make sure it is being called.

Also your calling it with -

callGameOver(“win”);

But your callGameOver function isn’t taking a parameter as far as I can see.

Dave [import]uid: 117617 topic_id: 33981 reply_id: 135107[/import]

As jensto says, your calling Director and your using StoryBoard. Was this written for Director and your converting it to Storyboard ?

I presume that is where module(…, package.seeall) is coming from. You don’t need that anymore.

Also I can’t see where you are creating the hudGroup either.

If you want to email me the code and images at thedavebaxter [at] gmail.com, I can take a look.

Dave
[import]uid: 117617 topic_id: 33981 reply_id: 135416[/import]

What do I write then? [import]uid: 128294 topic_id: 33981 reply_id: 135133[/import]

Put a print statement as the first line of the callGameOver function -

print(“callGameOver Entered”)

If this prints in the terminal, you know the function is being called.

When calling the function, just put -

callGameOver()

Dave [import]uid: 117617 topic_id: 33981 reply_id: 135161[/import]

Will do. [import]uid: 128294 topic_id: 33981 reply_id: 135476[/import]

I get this when I load the level.

[text]
mygame/level2.lua:22: unexpected symbol near ‘9999’
stack traceback:
level2.lua:22: unexpected symbol near '9999’stack traceback:
?: in function ‘gotoScene’
mygame/loading.lua:67: in function ‘_listener’
?: in function <?:531>
?: in function <?:226>
[/text]

Bare in mind this is what I have for the top.
[lua]module(…, package.seeall)
local storyboard = require(“storyboard”)
local scene = storyboard.newScene()

_W = display.contentWidth;
_H = display.contentHeight;
local button = {}
local buttonCover = {}
local buttonImages = {7,7, 8,8, 9,9, 10,10, 11,11, 12,12}

local lastButton
local background
local restartTimer
local timerInfo
local numSeconds = 40
local totSeconds = numSeconds
local counterSize = 50
local counter
local scoreText
local gameScore 9999
local totalButtons = 0
local secondSelect = 0
local checkForMatch = false
local gameOver [/lua]

And after that…
[lua]local callGameOver()
– Create all game over objects and insert them into the HUD group
print(“callGameOver Entered”)[/lua] [import]uid: 128294 topic_id: 33981 reply_id: 135183[/import]

You need to use what it’s giving you to find the error.

Where it says level2.lua:22 unexpected symbol near 9999.

That means in the file level2.lua at line 22 there is a problem near the word 9999.

So go to line 22 and what do you see ?

There is a = sign missing.

It’s not always obvious but once you learn to pick out the bits from the error it gets easier. Always work from the top of the error message as that will usually tell you where to start looking. The rest of the error message usually tells you what line called level2.lua and what function etc…

Dave [import]uid: 117617 topic_id: 33981 reply_id: 135227[/import]

Added = to line 22 , but I still got the same. Error message with loading.lua as well. So I checked it out.

[lua]-- Called immediately after scene has moved onscreen:
function scene:enterScene(event)
local group = self.view
local previous = storyboard.getPrevious()

if previous ~= “main” and previous then
storyboard.removeScene(previous)
end

local ready = function()

storyboard.gotoScene(“level”…loadLevel, “fromBottom”, 500)
end

timer.performWithDelay(1000, ready)

– INSERT code here (e.g. start timers, load audio, start listeners, etc.)


end[/lua]

Is there something wrong with line 67? [import]uid: 128294 topic_id: 33981 reply_id: 135286[/import]

No, the error message is just telling you what line called the file with the error.

I don’t understand why you are still getting the same error message if you fixed line 22.

You probably need to post all your code here and the error messages.

Dave [import]uid: 117617 topic_id: 33981 reply_id: 135306[/import]

In that case…

For the second level…

[lua]module(…, package.seeall)
local storyboard = require(“storyboard”)
local scene = storyboard.newScene()

_W = display.contentWidth;
_H = display.contentHeight;
local button = {}
local buttonCover = {}
local buttonImages = {7,7, 8,8, 9,9, 10,10, 11,11, 12,12}

local lastButton
local background
local restartTimer
local timerInfo
local numSeconds = 40
local totSeconds = numSeconds
local counterSize = 50
local counter
local scoreText
local gameScore = 9999
local totalButtons = 0
local secondSelect = 0
local checkForMatch = false
local gameOver

local callGameOver()
– Create all game over objects and insert them into the HUD group
print(“callGameOver Entered”)

– SHADE
local shade = display.newRect( 0, 0, 480, 320 )
shade:setFillColor( 0, 0, 0, 255 )
shade.alpha = 0

– GAME OVER WINDOW

gameOverDisplay = display.newImage( “gameOverScreen.png”)

local newScore = gameScore
setScore( newScore )

gameOverDisplay.x = 240; gameOverDisplay.y = 160
gameOverDisplay.alpha = 0

– INSERT ALL ITEMS INTO GROUP
hudGroup:insert( shade )
hudGroup:insert( gameOverDisplay )

– FADE IN ALL GAME OVER ELEMENTS
transition.to( shade, { time=200, alpha=0.65 } )
transition.to( gameOverDisplay, { time=500, alpha=1 } )

counter.isVisible = false

– MAKE SURE SCORE TEXT IS VISIBLE
scoreText.isVisible = false
scoreText.text = "Score: " … gameScore
scoreText.xScale = 0.5; scoreText.yScale = 0.5
scoreText.x = 280
scoreText.y = 160
scoreText:toFront()
timer.performWithDelay( 1000, function() scoreText.isVisible = true; end, 1 )

end
local myTimer = function()

numSeconds = numSeconds - 1
counter.text = "Time: " … tostring( numSeconds )
print(numSeconds)

print( button.numChildren )
if numSeconds == 0 then
callGameOver(“lose”)
end

end

local startTimer = function()
print(“Start Timer”)
timerInfo = system.getTimer()
end
local setScore = function( )

if gameScore < 0 then gameScore = 0; end

scoreText.text = "Score: "…gameScore

end

local gameLoop = function (event)

if gameOver == false then

local t = system.getTimer()

gameScore = gameScore - 3
setScore()

if t - timerInfo > 1000 then

timerInfo = system.getTimer()
myTimer()

end
end

end

local setScore = function( scoreNum )
local newScore = scoreNum

gameScore = newScore

if gameScore < 0 then gameScore = 0; end

scoreText.text = gameScore
scoreText.xScale = 0.5; scoreText.yScale = 0.5
scoreText.x = (480 - (scoreText.contentWidth * 0.5)) - 15
scoreText.y = 20
end

function game(object, event)

if gameOver == false then
if(event.phase == “began”) then
if(checkForMatch == false and secondSelect == 0) then
–Flip over first button
buttonCover[object.number].isVisible = false;
lastButton = object
checkForMatch = true
elseif(checkForMatch == true) then
if(secondSelect ==0 and lastButton ~= object) then
–Flip over second button
buttonCover[object.number].isVisible = false;
secondSelect = 1;
–If buttons do not match, flip buttons over
if(lastButton.myName ~= object.myName) then
timer.performWithDelay(1250, function()
checkForMatch = false;
secondSelect = 0;
buttonCover[lastButton.number].isVisible = true;
buttonCover[object.number].isVisible = true;
gameScore = gameScore - 500;
setScore()
end, 1)
–If buttons DO match, remove buttons
elseif(lastButton.myName == object.myName) then
timer.performWithDelay(1250, function()
checkForMatch = false;
secondSelect = 0;
lastButton:removeSelf();
object:removeSelf();
buttonCover[lastButton.number]:removeSelf();
buttonCover[object.number]:removeSelf();
totalButtons = totalButtons - 2

if totalButtons == 0 then callGameOver(“win”); end
end, 1)
end
end
end
end
end
end

function scene:createScene(event)
localGroup = self.view

lastButton = display.newImageRect(localGroup, “1.png”,75,75);
lastButton.myName = 1;
lastButton.alpha = 0

background = display.newImageRect(localGroup,“bg2.png”,320,480, true)
background.x = 160; background.y = 240

counter = display.newText("Time: "…numSeconds, 10, 8, native.systemFont, 20)
localGroup:insert(counter)

scoreText = display.newText("Score: "…gameScore, 200, 8, native.systemFont, 20)
localGroup:insert(scoreText)

local px = -20
local py

for count = 1,3 do
px = px + 90
py = 20

for insideCount = 1,4 do
py = py + 90

temp = math.random(1, #buttonImages)
button[count] = display.newImageRect(buttonImages[temp] … “.png”,75,75);

button[count].x = px;
button[count].y = py;

button[count].myName = buttonImage[temp]
button[count].number = totalButtons

localGroup:insert(button[count])

table.remove(buttonImages, temp)

buttonCover[totalButtons] = display.newImageRect(“button2.png”,75,75);
buttonCover[totalButtons].x = px; buttonCover[totalButtons].y = py;
localGroup:insert(buttonCover[totalButtons])
totalButtons = totalButtons + 1

button[count].touch = game
button[count]:addEventListener( “touch”, button[count] )
end
end

end

function scene:willEnterScene(event)
local group = self.view

end

function scene:enterScene(event)
local group = self.view

local start = function ()

startTimer()
Runtime:addEventListener(“enterFrame”,gameLoop)

end

timer.performWithDelay(500, start)
end

– Called when scene is about to move offscreen:
function scene:exitScene(event)
local group = self.view
end

– Called AFTER scene has finished moving offscreen:
function scene:didExitScene(event)
local group = self.view
end

– Called if/when overlay scene is displayed via storyboard.showOverlay()
function scene:overlayBegan(event)
local group = self.view
local overlay_scene = event.sceneName – overlay scene name
end

– Called if/when overlay scene is hidden/removed via storyboard.hideOverlay()
function scene:overlayEnded(event)
local group = self.view
local overlay_scene = event.sceneName – overlay scene name
end


– END OF YOUR IMPLEMENTATION

– “createScene” event is dispatched if scene’s view does not exist
scene:addEventListener(“createScene”, scene)

– “willEnterScene” event is dispatched before scene transition begins
scene:addEventListener(“willEnterScene”, scene)

– “enterScene” event is dispatched whenever scene transition has finished
scene:addEventListener(“enterScene”, scene)

– “exitScene” event is dispatched before next scene’s transition begins
scene:addEventListener(“exitScene”, scene)

– “didExitScene” event is dispatched after scene has finished transitioning out
scene:addEventListener(“didExitScene”, scene)

– “destroyScene” event is dispatched before view is unloaded, which can be
– automatically unloaded in low memory situations, or explicitly via a call to
– storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener(“destroyScene”, scene)

– “overlayBegan” event is dispatched when an overlay scene is shown
scene:addEventListener(“overlayBegan”, scene)

– “overlayEnded” event is dispatched when an overlay scene is hidden/removed
scene:addEventListener(“overlayEnded”, scene)


return scene[/lua]
levels.lua…
[lua]module(…, package.seeall)
local storyboard = require(“storyboard”)
local scene = storyboard.newScene()

local levels = 3

local localGroup = display.newGroup()

local background
local levelbutton = {}
local menubutton

local function pressLevel (event)

local obj = event.target
local bId = obj.id
_G.loadLevel = bId

if event.phase == “ended” then
storyboard.gotoScene(“loading”,“fromRight”,500)
end

end

local function pressMenubutton (event)
if event.phase == “ended” then
director:changeScene (“menu”)
end
end


– STORYBOARD FUNCTIONS

– Called when the scene’s view does not exist:
function scene:createScene(event)
localGroup = self.view
background = display.newImageRect (localGroup,“mainbackground.jpg”,640,960)
localGroup:insert(background)

for a = 1, levels, 1 do
local i = display.newImageRect(localGroup, “level”…a…“btn.png”,120,50)
i.x, i.y = 160, 140+ ((a-1)*60)
i.id = a
i:addEventListener (“touch”, pressLevel)
levelbutton[a] = i
end
menubutton = display.newImageRect (localGroup,“backbutton.png”,120,50)
menubutton.x = 160
menubutton.y = 350
menubutton:addEventListener (“touch”, pressMenubutton)

end

– Called BEFORE scene has moved onscreen:
function scene:willEnterScene(event)
local group = self.view


– This event requires build 2012.782 or later.


end

– Called immediately after scene has moved onscreen:
function scene:enterScene(event)
local group = self.view
end
– Called when scene is about to move offscreen:
function scene:exitScene(event)
local group = self.view
end

– Called AFTER scene has finished moving offscreen:
function scene:didExitScene(event)
local group = self.view
end

– Called if/when overlay scene is displayed via storyboard.showOverlay()
function scene:overlayBegan(event)
local group = self.view
local overlay_scene = event.sceneName – overlay scene name
end

– Called if/when overlay scene is hidden/removed via storyboard.hideOverlay()
function scene:overlayEnded(event)
local group = self.view
local overlay_scene = event.sceneName – overlay scene name
end


– END OF YOUR IMPLEMENTATION

– “createScene” event is dispatched if scene’s view does not exist
scene:addEventListener(“createScene”, scene)

– “willEnterScene” event is dispatched before scene transition begins
scene:addEventListener(“willEnterScene”, scene)

– “enterScene” event is dispatched whenever scene transition has finished
scene:addEventListener(“enterScene”, scene)

– “exitScene” event is dispatched before next scene’s transition begins
scene:addEventListener(“exitScene”, scene)

– “didExitScene” event is dispatched after scene has finished transitioning out
scene:addEventListener(“didExitScene”, scene)

– “destroyScene” event is dispatched before view is unloaded, which can be
– automatically unloaded in low memory situations, or explicitly via a call to
– storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener(“destroyScene”, scene)

– “overlayBegan” event is dispatched when an overlay scene is shown
scene:addEventListener(“overlayBegan”, scene)

– “overlayEnded” event is dispatched when an overlay scene is hidden/removed
scene:addEventListener(“overlayEnded”, scene)


return scene[/lua]
Menu
[lua]module(…, package.seeall)
local storyboard = require(“storyboard”)
local scene = storyboard.newScene()

local localGroup = display.newGroup()
local background
local playbtn
local function pressPlay (event)
if event.phase == “ended” then
storyboard.gotoScene(“levels”,“fromTop”,500)
end
end


– STORYBOARD FUNCTIONS

– Called when the scene’s view does not exist:
function scene:createScene(event)
localGroup = self.view

background = display.newImage (“BG.png”)
localGroup:insert(background)

playbtn = display.newImage (“playbtn.jpg”)
playbtn.x = 160
playbtn.y = 225
localGroup:insert(playbtn)
playbtn:addEventListener (“touch”, pressPlay)
end

– Called BEFORE scene has moved onscreen:
function scene:willEnterScene(event)
local group = self.view


– This event requires build 2012.782 or later.


end

– Called immediately after scene has moved onscreen:
function scene:enterScene(event)
local group = self.view
end
– Called when scene is about to move offscreen:
function scene:exitScene(event)
local group = self.view
end

– Called AFTER scene has finished moving offscreen:
function scene:didExitScene(event)
local group = self.view
end

– Called if/when overlay scene is displayed via storyboard.showOverlay()
function scene:overlayBegan(event)
local group = self.view
local overlay_scene = event.sceneName – overlay scene name
end

– Called if/when overlay scene is hidden/removed via storyboard.hideOverlay()
function scene:overlayEnded(event)
local group = self.view
local overlay_scene = event.sceneName – overlay scene name
end


– END OF YOUR IMPLEMENTATION

– “createScene” event is dispatched if scene’s view does not exist
scene:addEventListener(“createScene”, scene)

– “willEnterScene” event is dispatched before scene transition begins
scene:addEventListener(“willEnterScene”, scene)

– “enterScene” event is dispatched whenever scene transition has finished
scene:addEventListener(“enterScene”, scene)

– “exitScene” event is dispatched before next scene’s transition begins
scene:addEventListener(“exitScene”, scene)

– “didExitScene” event is dispatched after scene has finished transitioning out
scene:addEventListener(“didExitScene”, scene)

– “destroyScene” event is dispatched before view is unloaded, which can be
– automatically unloaded in low memory situations, or explicitly via a call to
– storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener(“destroyScene”, scene)

– “overlayBegan” event is dispatched when an overlay scene is shown
scene:addEventListener(“overlayBegan”, scene)

– “overlayEnded” event is dispatched when an overlay scene is hidden/removed
scene:addEventListener(“overlayEnded”, scene)


return scene[/lua]
If you want me to post the code for level 1 which is the only level that works right now, I will. [import]uid: 128294 topic_id: 33981 reply_id: 135402[/import]

I still do think you need to look into the displayGroup management in your game. I can not see that the hudGroup is ever created in the first place.

I am not shure how appropriate it is to mix director and storyboard in the same project. I would pick one and stick to it, since they both removes objects in each scene (I guess).

(Sorry if I sound like a looping record…) [import]uid: 25729 topic_id: 33981 reply_id: 135405[/import]

As jensto says, your calling Director and your using StoryBoard. Was this written for Director and your converting it to Storyboard ?

I presume that is where module(…, package.seeall) is coming from. You don’t need that anymore.

Also I can’t see where you are creating the hudGroup either.

If you want to email me the code and images at thedavebaxter [at] gmail.com, I can take a look.

Dave
[import]uid: 117617 topic_id: 33981 reply_id: 135416[/import]

Will do. [import]uid: 128294 topic_id: 33981 reply_id: 135476[/import]