EnterFrame doesnt get removed?

Hello,

I have 2 scenes now, a house scene and a school scene. In both scenes it should be possible to enter a world map where you can choose togo to another scene. Everything works fine as long as both scenes are starting for the first time

For example the game starts in the house scene, and then you enter the world map and open the school scene. Works perfectly fine.

But when I am i the school scene and go back to the house scene, a lot of things go wrong. This is because when you open the house scene it will not restart/create the whole scene, but only enter the scene. Now I thought i fixed that by assigning most variables, which should be set to the original position and amount, to assign them all in the enterScene event. Also I put the addEventListeners in the enterScene event, (and nowhere else).But now I get another error.

When I exit the school scene to go back to the house scene. It should remove all event listeners and set a couple of variables to nil

[lua]function scene:exitScene( event )

local group = self.view
Runtime:removeEventListener(“touch”, onTouch )
Runtime:removeEventListener(“enterFrame”, EnterFrame)
for o=1,#characters do
characters[o]:addEventListener( “tap”, onTapNPC )
end
print(“exitScene”)
loader:removeSelf()
loader = nil
player = nil
gf = nil
mom = nil
lhGroup:removeSelf()
lhGroup = nil

physics.stop()
end[/lua]

BUT now when the game has already entered the house scene, and by some print functions I can see it already did this and also should have removed all the listeners in the exitScene event in the school. I get and error from the school scene, because it is still running the enterFrame event from the SCHOOL scene!

I copied all the code from both scenes so both scenes are exactly the same (Apart from the names in some tags and the print functions).

So what really confuses me is that this enterFrame problem doesn’t happen when you go from the house scene to the school scene. But when I go from the school to house scene this problem occurs. Even though the removeEventListener for the enterFrame has been executed [import]uid: 118839 topic_id: 33866 reply_id: 333866[/import]

Not too sure without seeing more.
Is the function to be removed definitely called EnterFrame? I’m referring more to the upper/lower case letters rather than the name itself.
If both scenes have a function called EnterFrame, are they both local to the scene, or are they global? It could be calling the wrong EnterFrame function.

Your code certainly looks ok, but as I say there could be something else in there causing the problem. [import]uid: 84115 topic_id: 33866 reply_id: 134629[/import]

I found the problem yesterday, the problem was that alot of functions where global, somehow I didn’t realize this because I first made 1 level, and it worked correctly. So I copied it thinking it would work correctly too. But off course this was giving problems. So now I am making external files for some functions, that can be runned from all levels, or I make the functions local. This solves the whole problem. I did not understand corona and LUA correctly yet I guess. I thought every function inside a scene would be local by itself, or something like that. But now I know what the problem is.

Thanks for your reply :slight_smile: [import]uid: 118839 topic_id: 33866 reply_id: 134793[/import]

Not too sure without seeing more.
Is the function to be removed definitely called EnterFrame? I’m referring more to the upper/lower case letters rather than the name itself.
If both scenes have a function called EnterFrame, are they both local to the scene, or are they global? It could be calling the wrong EnterFrame function.

Your code certainly looks ok, but as I say there could be something else in there causing the problem. [import]uid: 84115 topic_id: 33866 reply_id: 134629[/import]

I found the problem yesterday, the problem was that alot of functions where global, somehow I didn’t realize this because I first made 1 level, and it worked correctly. So I copied it thinking it would work correctly too. But off course this was giving problems. So now I am making external files for some functions, that can be runned from all levels, or I make the functions local. This solves the whole problem. I did not understand corona and LUA correctly yet I guess. I thought every function inside a scene would be local by itself, or something like that. But now I know what the problem is.

Thanks for your reply :slight_smile: [import]uid: 118839 topic_id: 33866 reply_id: 134793[/import]