timer, on or off?

how can i see if a timer it’s on or off?

i have tryed to print the timer but only show some codes and i dont know if his on or off

someone? [import]uid: 23063 topic_id: 10485 reply_id: 310485[/import]

local myTimer = timer.performWithDelay(100,asd)

if myTimer then
print(“running”)
else
print(“not running”)
end [import]uid: 12482 topic_id: 10485 reply_id: 38197[/import]

 timer.cancel ( timer1 )  
 timer.cancel ( E\_bomb1Spawner )  
 timer.cancel ( E\_bomb1SpawnerSlow )  
  
 if timer1 then  
 print( "timer1" )  
 else  
 print( "sem timer1" )  
 end  
  
 if E\_bomb1Spawner then  
 print( "E\_bomb1Spawner" )  
 else  
 print( "sem E\_bomb1Spawner" )  
 end  
  
 if E\_bomb1SpawnerSlow then  
 print( "E\_bomb1SpawnerSlow" )  
 else  
 print( "sem E\_bomb1SpawnerSlow" )  
 end  

in my print i’m getting the timers… what i’m doing wrong? :S
i want to stop this timers =l [import]uid: 23063 topic_id: 10485 reply_id: 38203[/import]

is this something that u want ??
[lua] local rect = display.newRect(0,0,100,100)

local function timer1()
rect.x = rect.x + 1
end
t = timer.performWithDelay(20,timer1,0)

local function cancelTimer()
timer.cancel(t)
t = nil
end
timer.performWithDelay(1500,cancelTimer,1)
local function callMe()
if t then
print(“yup”)
else
print(“nup”)
end
end
Runtime:addEventListener(“enterFrame”,callMe)[/lua] [import]uid: 12482 topic_id: 10485 reply_id: 38207[/import]

i have use timer1 = nil after cancel he and works… but when i restart the scene I have a error “attempt to index a nil value”
when i call the gameover

any idea? how can i set up timer1 again after restart scene? [import]uid: 23063 topic_id: 10485 reply_id: 38211[/import]

whenever you restart at that time your code is also reloaded so this error should not be in standard scenario must be some mistake in ur code try to find and make sure your timer is over there when u restart

:slight_smile: [import]uid: 12482 topic_id: 10485 reply_id: 38212[/import]

but this problem start when i put timer1 = nil
and he only show up when i call gameover =S [import]uid: 23063 topic_id: 10485 reply_id: 38214[/import]

don’t know what u r saying find some other way like,

[lua]local rect = display.newRect(0,0,100,100)

local function timer1()
rect.x = rect.x + 1
end
t = timer.performWithDelay(20,timer1,0)
local timerIsOn = true
local function cancelTimer()
timer.cancel(t)
timerIsOn = false
end
timer.performWithDelay(1500,cancelTimer,1)
local function callMe()
if timerIsOn then
print(“yup”)
else
print(“nup”)
end
end
Runtime:addEventListener(“enterFrame”,callMe)[/lua]

also i don’t understand why this

[lua]if timer1 then
print( “timer1” )
else
print( “sem timer1” )
end[/lua] [import]uid: 12482 topic_id: 10485 reply_id: 38216[/import]

this is to check if timer1 is running after gameover or not [import]uid: 23063 topic_id: 10485 reply_id: 38217[/import]

ok got that at the gameOver you are cancelling timer and when u restart it is not working right?

if yes plz post sample code so i can look
[import]uid: 12482 topic_id: 10485 reply_id: 38218[/import]

[lua]timer.performWithDelay(1500,cancelTimer,1)[/lua]

I think you forgot to cancel this timer. Try canceling all the timers before you change Scene or restart.

[import]uid: 12455 topic_id: 10485 reply_id: 38227[/import]