Hello
this is how I start the timers
local composer = require( "composer" ) local scene = composer.newScene() timersArray = {} function scene:create( event ) function performTimedEvents(timeString) local function onTimer( event ) local params = event.source.params if(arg == 5) then timer.cancel( event.source ) return end end for i=1,10 do --print("performWithDelay "..sliceStars(timeString)[i]) timersArray[i] = timer.performWithDelay( 1000\*sliceStars(timeString)[i], onTimer ) timersArray[i].params = { n = i } end end performTimedEvents(pagesTimers[currentPage]) end
this is how I cancel the timers (before leaving the scene) but they are still there when I leave the scene, the timers are still printing stuff into the console… notice this specific line timer.cancel(timersArray[j])
function flushTimers() pageSequence(5) print("QQQtimersArray") print\_r(timersArray) for j=1,#timersArray do print("didCancelTimer "..j) timer.cancel(timersArray[j]) --timer.pause(timersArray[j]) timersArray[j] = nil end timersArray = {} print\_r(timersArray) print("didReturn"); end
also why scene:hide is not being fired, it used to work at old times when we had storyboard with exit, but this hide callback is not getting called, please help
function scene:hide( event ) print("YYY\_hide\_!!!") local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then print("YYY\_hide\_will") -- Called when the scene is on screen (but is about to go off screen) -- Insert code here to "pause" the scene -- Example: stop timers, stop animation, stop audio, etc. elseif ( phase == "did" ) then print("YYY\_hide\_did") -- Called immediately after scene goes off screen end end function scene:destroy( event ) local sceneGroup = self.view -- Called prior to the removal of scene's view -- Insert code here to clean up the scene -- Example: remove display objects, save state, etc. --myAudioPlayer = nil --audio.stop() --audio.rewind(1) flushTimers() --timersArray = nil print("YYY\_destroy\_did") end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene )
by the way, this is how I remove the current scene
composer.removeScene("currentScene") composer.gotoScene("nextScene",effectOptions)
please help!