Timer

How can i pause the timer when the seconds = 0 ??

local seconds = 0     function time(  )      seconds = seconds-1      secondsT.text= seconds          if seconds == 0 then          print ("seconds = 0")          physics.start()            end end local cro = timer.performWithDelay(1000,time, 0 )

 

Maybe there’s a typo, but since seconds starts at 0 and decrements before the ‘if’ statement, your code will never see seconds==0 (the first thing it sees is seconds==-1).

Have you tried it with seconds starting at 10, e.g. ??

local seconds = 5 local secondsT = display.newText("", 10, 10) local physics = require "physics" physics.start() local cro function time( ) seconds = seconds-1 secondsT.text= seconds if seconds == 0 then print ("seconds = 0") physics.start() timer.cancel(cro) end end cro = timer.performWithDelay(1000,time, 0 )

This starts a timer at 5 and counts backwards to 0 then stops…  hope it helps.

Maybe there’s a typo, but since seconds starts at 0 and decrements before the ‘if’ statement, your code will never see seconds==0 (the first thing it sees is seconds==-1).

Have you tried it with seconds starting at 10, e.g. ??

local seconds = 5 local secondsT = display.newText("", 10, 10) local physics = require "physics" physics.start() local cro function time( ) seconds = seconds-1 secondsT.text= seconds if seconds == 0 then print ("seconds = 0") physics.start() timer.cancel(cro) end end cro = timer.performWithDelay(1000,time, 0 )

This starts a timer at 5 and counts backwards to 0 then stops…  hope it helps.