So I have my code set up to go to a certain scene if a variable reaches a certain number:
function flylistener() if spawnedflies \> 15 then storyboard.gotoScene( "gameover" ) else end end
I call that function every 5 seconds, it works fine.
In the exitscene listener I have the following code:
-- Called when scene is about to move offscreen: function scene:exitScene( event ) local group = self.view local flygroup = self.view physics.stop() timer.cancel(listenertimer) listenertimer = nil timer.cancel(spawntimer) spawntimer = nil spawn = nil buttonListener = nil listener = nil spawner = nil spawn = nil flylistener = nil end
I have this to try to cancel the timers (which are set to said variable names) then unload the variables, plus assign nil to all the functions I have set up. However, when the exitscene is called (when the gameover scene is called), then it tells me that timer.cancel is trying to index a nil value. Any idea why it won’t cancel?
EDIT: It would appear that IE removed the proper code formatting. Apologies.