Function still running after composer.removeScene()

Hello Corona Community,

I have a timer.delay function in my main game scene. The function is called after 60 seconds into the game. The problem is I also have a pause button. If the user presses the pause button in the game it goes to the menu. Then after 60 seconds on the menu the timer.delay function gets called while in the menu. I removed the main game scene with composer.removeScene() when the user exits the game to the menu so why is the timer.delay function being called?

Any help will be apprecieated. :slight_smile:

Hello,

calling composer.removeScene() removes the scene’s display group, but does not do any cleanup beyond that - active timers will continue to run, and Runtime listeners from the removed scene will continue unless you explicitly remove them. There are many ways you can manage “cleanup” of a scene’s timers, listeners, etc, but the usual way is to add code to the scene:hide() block of code in your scene that ties up these loose ends.

And pardon the bit of self-promotion, but you might want to check out my modified “Timer 2.0” library that allows you to cancel or pause all active timers with a single “timer.cancel()” or “timer.pause()” call - no need to explicitly state the timers to be cancelled (as is the case with the built-in timer library). It’s free, and you can download it and read the documentation on it here: http://www.jasonschroeder.com/2015/02/25/timer-2-0-library-for-corona-sdk/

Good luck!

Thank you so much shroederapps I will clean up my timers.

Also, your timer library is AMAZING THANK YOU. ITS JUST SO GOOD.

:slight_smile:

Hello,

calling composer.removeScene() removes the scene’s display group, but does not do any cleanup beyond that - active timers will continue to run, and Runtime listeners from the removed scene will continue unless you explicitly remove them. There are many ways you can manage “cleanup” of a scene’s timers, listeners, etc, but the usual way is to add code to the scene:hide() block of code in your scene that ties up these loose ends.

And pardon the bit of self-promotion, but you might want to check out my modified “Timer 2.0” library that allows you to cancel or pause all active timers with a single “timer.cancel()” or “timer.pause()” call - no need to explicitly state the timers to be cancelled (as is the case with the built-in timer library). It’s free, and you can download it and read the documentation on it here: http://www.jasonschroeder.com/2015/02/25/timer-2-0-library-for-corona-sdk/

Good luck!

Thank you so much shroederapps I will clean up my timers.

Also, your timer library is AMAZING THANK YOU. ITS JUST SO GOOD.

:slight_smile: