[Resolved] Restart Game Button -- Please Help

Hey everyone/anyone that can help…

I am trying to add a restart game button that comes up when gameover is displayed in this game. Restart button comes up but when you press it it doesn’t restart the game it just gives you a screen with the background only. I don’t know what I am doing wrong… Can somebody please help me on this? I have been trying for a while now :frowning:

Code goes like this… debugger comes up with no clues to as what i am doing wrong
function gameOver()
local gameOverSound = audio.loadSound(“SoundGameOver.wav”)
audio.play(gameOverSound)
audio.fadeOut{channel = soundBackgroundChannel, time = 2000}
stopListeners()
local gameOverImage = display.newImageRect( game, “GameOver.png”, 425, 79 )
gameOverImage.x = HALF_WIDTH
gameOverImage.y = HALF_HEIGHT

local replayButton = ui.newButton{
default = “replayButton.png”,
over = “replayButton.png”,
onRelease = function(event)
removeSelf(); startGame() end
}
game:insert(replayButton)

replayButton.x = display.contentWidth / 2
replayButton.y = gameOverImage.y + gameOverImage.height / 2 + replayButton.height / 2
end

Thank you soooooo much just for taking the time to look at this and help…

Andrew [import]uid: 165071 topic_id: 32704 reply_id: 332704[/import]

Would need to see start game function.

Also, please post code in < lua > and < /lua > tags, it is readable that way. [import]uid: 52491 topic_id: 32704 reply_id: 130055[/import]

Would need to see start game function.

Also, please post code in < lua > and < /lua > tags, it is readable that way. [import]uid: 52491 topic_id: 32704 reply_id: 130055[/import]

Sorry about not writing out in proper format… Am still learning… I still can’t believe that before August I knew nothing about programming… come a long way thanks to your guidance via these forums and your site etc etc etc (really admire your commitment and knowledge)!! And you did it again :slight_smile: After reading your reply I had another look and the answer was right in front of me (after soooo long lol)… Well i copied the startGame code from my main.lua into my replay section in my game.lua and added game:removeSelf()… Just fiddling with Soundbackground now as only plays twice then not at all after pressing replay… The sound effects play every time though?!? odd lol… Anyway Thanks again Peach, you are Awesome!!! [import]uid: 165071 topic_id: 32704 reply_id: 130093[/import]

Sorry about not writing out in proper format… Am still learning… I still can’t believe that before August I knew nothing about programming… come a long way thanks to your guidance via these forums and your site etc etc etc (really admire your commitment and knowledge)!! And you did it again :slight_smile: After reading your reply I had another look and the answer was right in front of me (after soooo long lol)… Well i copied the startGame code from my main.lua into my replay section in my game.lua and added game:removeSelf()… Just fiddling with Soundbackground now as only plays twice then not at all after pressing replay… The sound effects play every time though?!? odd lol… Anyway Thanks again Peach, you are Awesome!!! [import]uid: 165071 topic_id: 32704 reply_id: 130093[/import]

Hey Andrew-

No worries at all, just a heads up for future reference.

I don’t know that I can take credit for this one; I suspected the problem lay there but you’re the one who tracked it down and made it work - good for you! And thanks for the kind words, they are most appreciated.

Keep it up - think where you could be by next August!

Marking as resolved, hope to see more of you around the forum!

Peach :slight_smile:

PS - If you elaborate a little further on sound issues and show exact code may be able to assist, if needed. [import]uid: 52491 topic_id: 32704 reply_id: 130195[/import]

Hey Andrew-

No worries at all, just a heads up for future reference.

I don’t know that I can take credit for this one; I suspected the problem lay there but you’re the one who tracked it down and made it work - good for you! And thanks for the kind words, they are most appreciated.

Keep it up - think where you could be by next August!

Marking as resolved, hope to see more of you around the forum!

Peach :slight_smile:

PS - If you elaborate a little further on sound issues and show exact code may be able to assist, if needed. [import]uid: 52491 topic_id: 32704 reply_id: 130195[/import]