Help recalling a file.lua - need guidance on cleaning up.

I tried to follow directions on making a game where you have a level.lua that calls game.lua and then when the game.lua is over it calls level.lua again and keeps going back and forth like that until game is finished.

But, For some reason it doesn’t do anything when I call level.lua again.

My guess is because I didn’t clean up level.lua when I called game.lua.  But, I haven’t seen any tutorials on HOW to clean up.  All I see is over and over “clean up your …” but I haven’t seen any examples. 

Is there any REAL LIFE example (programs with LOTS of timers, display objects, etc that needs to be cleaned up) that shows HOW to clean up?  I mean I read where you have to cancel your timers and get rid of your display timers, but I haven’t seen a REAL example of that.  Anyone got one?

If I clean up and still not work, then I will show my code, but I think this is the problem.

Thanks for your help!

See:  https://github.com/coronalabs/sample-game-project

This is a complete game project that shows the composer flow.  It doesn’t have lots of timers and such, but it should have enough to demonstrate the concepts.  The game.lua is full of comments explaining why things are done the way they are.

Rob

if your using your own code to change scenes (like i do) you need to create a removeAllObjects function that you need to call before you pass to the next scene.

in a scene i put all my objects in a table or in a group.

if its a transtion i put it in a table for transitions

if its a timer i put in in a table for timers.

send those tables to the remove function and remove all from there.

example to cancel all timers in a scene would be:

 if obj.timers then for i=#obj.timers, 1, -1 do if obj.timers[i] then timer.cancel(obj.timers[i]) obj.timers[i]=nil end end end obj.timers=nil

See:  https://github.com/coronalabs/sample-game-project

This is a complete game project that shows the composer flow.  It doesn’t have lots of timers and such, but it should have enough to demonstrate the concepts.  The game.lua is full of comments explaining why things are done the way they are.

Rob

if your using your own code to change scenes (like i do) you need to create a removeAllObjects function that you need to call before you pass to the next scene.

in a scene i put all my objects in a table or in a group.

if its a transtion i put it in a table for transitions

if its a timer i put in in a table for timers.

send those tables to the remove function and remove all from there.

example to cancel all timers in a scene would be:

 if obj.timers then for i=#obj.timers, 1, -1 do if obj.timers[i] then timer.cancel(obj.timers[i]) obj.timers[i]=nil end end end obj.timers=nil