ok so in the onCollision code when the circle collides with the box i want the 1) game scene to get remove so the circles and box disappear and for it to go back to the menu scene… how is it the correct way to do this?
Since your accelerometer is still going, it will blow up a couple frames after box gets removed, when that becomes just a lowly table.
Probably the best bet is to set box to nil after you remove it, then do:
local function onAccelerate( event ) if box then -- ADD THIS if box.x \> display.contentWidth \* 0.1 and box.x \< display.contentWidth \* 0.9 then box.x = box.x + (event.xInstant) \* 200 end if box.x \> display.contentWidth \* 0.9 then box.x = display.contentWidth \* 0.89 end if box.x \< display.contentWidth \* 0.1 then box.x = display.contentWidth \* 0.11 end end end
You’re also removing only one of your circles, whereas you probably want to do the whole bunch. You could actually load all of them (and the box) into a group, then just remove that instead. If you check the docs, you’ll see that all the shape creator functions can take a group as their first argument.
If you plan to come back to the scene (and I assume you’ll eventually want to, though it looks like you’re removing it, at the moment), it’s good practice to clean up after yourself, so in addition to box, you should set your circleTimer and circle to nil (when you remove a table, all its members go away too, so you don’t have to set them one by one to nil ), after doing your removes / cancels / etc. In this way, your scene looks like new, so re-entering is no different than entering it the first time. Simply initialize all your variables in the scene’s “show” listener (just in the “did” phase, in case you haven’t done one yet; otherwise, it’ll happen twice and double up your timer and collision handler) and you’re good to go.
Thanks for the help
my question now is how to stop litterly my whole game.lua on collision and just go back to menu.lua… like litterly make it like game.lua never existed… is that possible?
Well, pretty much just do all those sorts of things. Consider what it looks like when you start your level, and try to put it back in that state. Sometimes, if you have dependencies, you’ll need to do these in a certain order (often, reverse order of creation).
Also, see the code snippet in my last post, in particular the “ADD THIS”. That’s very likely the problem you’re encountering as described in your other topic. It’s explained above the snippet.
can you look at this post?
https://forums.coronalabs.com/topic/57461-attempt-to-index-upvalue-box-a-nil-value/
I did. That’s what I meant in my last paragraph. 
Look at the post above this, where I provided an updated onAccelerate function. Notice the “if box then” check.
HOLY S***!!! thanks man!! sorry for the language i never curse unless i step on a lego but this problem has been pissing me off! thanks a million!