Moving between scenes

So, I have a game. It’s has a menu.lua which has a button to go to the maingame file. Game ends goes to a gameover.lua

That all works great.

Now, the problem is, in the gameover.lua I have a button that says “replay”. You click “replay” I have it jump over to the menu.lua - no problem.

No, for some reason, I click “play” again, and it breaks. I get a director error.

Director ERROR: Failed to execute new ( params ) function on ‘coindrop’

Please forgive me for my unfailing “noobness” in LUA coding.

Am I suppose to be unloading code or something? Is the program still running my coindrop file?

I’m not sure exactly what I’m doing wrong … or how much code I should post. BUT … here is my menu.lua

  
module(..., package.seeall)  
  
--====================================================================--  
-- SCENE: [C2 Synergy - Menu]  
--====================================================================--  
  
--[[  
  
 - Version: [1.0]   
 - Made by: [name]  
 - Website: [url]  
 - Mail: [mail]  
  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
 - INFORMATION  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
  
 - [Your info here]  
  
--]]  
  
new = function ( params)  
  
 local ui = require ("ui")  
 ------------------  
 -- Groups   
 ------------------  
  
 local localGroup = display.newGroup()  
  
 ------------------  
 -- Your code here  
 ------------------  
  
 local textObject = display.newText( "C2 Synergy+", 1024 /1.5, 250, "DIN 1451 Std", 76 )  
 textObject:setTextColor( 176, 23, 31 )  
  
  
 local bt01t = function ( event )  
 if event.phase == "release" then  
  
 director:changeScene( "coindrop", "moveFromTop" )  
 end  
 end  
  
  
local bt01 = ui.newButton{  
 default = "play-red.png",  
 over = "play-faded.png",  
 onEvent = bt01t,  
 id = "bt01"  
 }  
 bt01.x = 1024 /1.25  
 bt01.y = 768 /2  
  
display.newImage ("coin-blue.png", 20, 70)  
blueTextdesc = display.newText ("Some babble about this. +10 points", 150, 100, nil, 18)  
 blueTextdesc:setTextColor(255,255,255)  
  
display.newImage ("coin-purple.png", 20, 170)  
purpleTextdesc = display.newText ("Some babble about this. +25 points", 150, 200, nil, 18)  
 purpleTextdesc:setTextColor(255,255,255)  
  
display.newImage ("coin-red.png", 20, 270)  
redTextdesc = display.newText ("Some babble about this. +75 points", 150, 300, nil, 18)  
 redTextdesc:setTextColor(255,255,255)  
  
display.newImage ("coin-green.png", 20, 370)  
greenTextdesc = display.newText ("Some babble about this. +100 points", 150, 400, nil, 18)  
 greenTextdesc:setTextColor(255,255,255)  
  
  
display.newImage ("coin-gold.png", 20, 470)  
goldTextdesc = display.newText ("Some babble about this. +250 points", 150, 500, nil, 18)  
 goldTextdesc:setTextColor(255,255,255)  
  
  
display.newImage ("bomb.png", 20, 600)  
goldTextdesc = display.newText ("This is bad. Makes the game end.", 150, 650, nil, 18)  
 goldTextdesc:setTextColor(255,255,255)  
 ------------------  
 -- MUST return a display.newGroup()  
 ------------------  
  
 return localGroup  
  
end  
  

And here is my gameover.lua

[code]

module(…, package.seeall)

new = function ()


– Groups

local localGroup = display.newGroup()


– Your code here

local textObject = display.newText( “GAME OVER”, 1024 /1.5, 250, “DIN 1451 Std”, 76 )
textObject:setTextColor( 255, 223, 231 )

local bt01t = function ( event )
if event.phase == “release” then
director:changeScene( “menu”, “moveFromTop”)
end
end

local bt01 = ui.newButton{
default = “replayButton.png”,
over = “replayButton.png”,
onEvent = bt01t,
id = “bt01”
}
bt01.x = 1024 /1.25
bt01.y = 768 /2


– MUST return a display.newGroup()

return localGroup

end

[/code] [import]uid: 97023 topic_id: 17016 reply_id: 317016[/import]

You have to put display objects into the group otherwise they will not be freed and cause problems.
So:

localGroup:insert(bt01)
Also name your images and text.

blueCoin = display.newImage (“coin-blue.png”, 20, 70)
localGroup:insert(blueCoin)
localGroup:insert(blueTextdesc)
etc. [import]uid: 47300 topic_id: 17016 reply_id: 63865[/import]