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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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

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.

views:1406 update:2011/10/29 17:13:10
corona forums © 2003-2011