Timer.cancel problem

I am trying to to cancel my timer when the ball is tapped but it’s not working , and I’ve tried multiple ways .

function timerDown() timeLimit = timeLimit-1 timeLeft.text = timeLimit if(timeLimit==0)then storyboard.gotoScene("maxtime", "fade", 400) end end timer.performWithDelay(1000,timerDown,timeLimit) function onBallTap( event ) timer.cancel( timer ) storyboard.gotoScene("restart", "fade", 400) end function scene:enterScene(event) Ball:addEventListener( "tap", onBallTap ) end function scene:exitScene(event) Ball:removeEventListener( "tap", onBallTap ) end

Have you tried actually applying the  timer tag to the timer call itself? Because right now, it’s an anonymous timer with no tag associated with it. I think you want to do something like:

local timer timer=timer.performWithDelay(1000,timerDown,timeLimit)

I do this.

local timerrr = timer.performWithDelay( 1000, timerDown, timeLimit ) timer.cancel(timerrr)

good point @infisnyp, you can’t use  timer as a tag as it overwrites the entire  timer.* API. Using something unique besides  timer as the tag is the best bet.

Have you tried actually applying the  timer tag to the timer call itself? Because right now, it’s an anonymous timer with no tag associated with it. I think you want to do something like:

local timer timer=timer.performWithDelay(1000,timerDown,timeLimit)

I do this.

local timerrr = timer.performWithDelay( 1000, timerDown, timeLimit ) timer.cancel(timerrr)

good point @infisnyp, you can’t use  timer as a tag as it overwrites the entire  timer.* API. Using something unique besides  timer as the tag is the best bet.