"game over" question from a beginner

Hey all,

I’m working on building my first game and have hit a roadblock. My game works like this:

  1. Screen 1 - a welcome screen with a “play button”
  2. Hitting the play button takes you into the game
  3. When the player dies, it’s supposed to give you an option to start over, but this is not working. The “game over” text displays, but it just stays there and never actually restarts the game.

function gameOver()
gameOverText = display.newText(“Game Over”, 50, 240, native.systemFontBold, 40)
local function removeGOText()
gameOverText:removeSelf()
end

timer.performWithDelay(2000, removeGOText)

player:removePlayer()
Runtime:removeEventListener(“enterFrame”, runtimeListener)
Runtime:removeEventListener(“accelerometer”, accelerometerCall)
Runtime:removeEventListener(“touch”, touchListener)

loader:removeAllSprites()
localGroup = nil
timer.performWithDelay(2000, startOver)
end

function startOver()
loadLevel()
Runtime:addEventListener(“enterFrame”, runtimeListener)
Runtime:addEventListener(“accelerometer”, accelerometerCall)
Runtime:addEventListener(“touch”, touchListener)

end
Sorry about any formatting issues, I’m copying and pasting. Everything in the game works fine except for this part. Hoping someone can point out where I’ve gone wrong. Thank you :slight_smile:
[import]uid: 125387 topic_id: 22354 reply_id: 322354[/import]

You are calling your startOver() function before it has been referenced. Try moving it above the gameOver() function and see if that works. [import]uid: 93133 topic_id: 22354 reply_id: 89106[/import]

Thank you for your reply. I will try your suggestion and report back :slight_smile: [import]uid: 125387 topic_id: 22354 reply_id: 89107[/import]

Hi there,

I tried, but it didn’t help :frowning: It just stays at the “game over” screen.

This is what the code looks like currently:

[code]function startOver()
loadLevel()
Runtime:addEventListener(“enterFrame”, runtimeListener)
Runtime:addEventListener(“accelerometer”, accelerometerCall)
Runtime:addEventListener(“touch”, touchListener)

end

function gameOver()
gameOverText = display.newText(“Game Over”, 50, 240, native.systemFontBold, 40)

local function removeGOText()
gameOverText:removeSelf()
end

timer.performWithDelay(2000, removeGOText)

player:removePlayer()
Runtime:removeEventListener(“enterFrame”, runtimeListener)
Runtime:removeEventListener(“accelerometer”, accelerometerCall)
Runtime:removeEventListener(“touch”, touchListener)

loader:removeAllSprites()
localGroup = nil
timer.performWithDelay(2000, startOver)
end
[/code]

Basically it seems like the local function removeGOText() and everything below that is not firing. [import]uid: 125387 topic_id: 22354 reply_id: 89149[/import]

I feel like I’ve followed every tutorial to a tee, but it still doesn’t work. I’m at a loss :frowning: [import]uid: 125387 topic_id: 22354 reply_id: 89291[/import]

Hi deadlights,

I think the part where you have:

  
 function gameOver()  
gameOverText = display.newText("Game Over", 50, 240, native.systemFontBold, 40)  
   
local function removeGOText()  
gameOverText:removeSelf()  
end  
  

… needs to change to:

local gameOver = function()  
  
 gameOverText = display.newText("Game Over", 50, 240, native.systemFontBold, 40)  
  
end  
  
local removeGoText = function()  
  
 gameOverText:removeSelf()  
  
end  
  
 timer.performWithDelay(2000, removeGOText)  

I haven’t test this and see if it works, I thought I would help you out with some of the function lay out from what you have. This would be a good start to solving your problem. Let me know if this helps or not. :slight_smile:

Essentially, you had a function inside another function, which is okay, but in your case, you didn’t ‘END’ the removeGOText() function… it’s just a call for disaster. If anything it’s always a good habit to end your functions properly. [import]uid: 75258 topic_id: 22354 reply_id: 89367[/import]

Thank you so much for your reply. I modified my code, and prayed, but it wouldn’t run at all until I removed the “end” in the gameOver function. So currently it looks like this, but of course still doesn’t work.

local gameOver = function()  
 gameOverText = display.newText("Game Over", 50, 240, native.systemFontBold, 40)  
  
local removeGOText = function()  
 gameOverText:removeSelf()  
end  

I think you’re right about my function layout, it’s all messed up. I followed so many tutorials and ended up completely confused and now it’s a garbled mess!
[import]uid: 125387 topic_id: 22354 reply_id: 89383[/import]