How can i see if a timer started?

so i have a timer and it starts after 4 seconds

i have a oncollision function that sometimes will stop the timer before 4 seconds… 

and that gives me an error because the timer isnt there to be stopped… so i was wondering how can i make this timer only stop if it has started… maybe something like this?

local function stopTimer() if stopTimer.status == "began" then timer.stop(theTimerWillBeHere) end end -- that is whats supposed to stop it.. ------------ stopTimer = timer.performWithDelay( 4000, updateScore, 1 ) -- this is the timer.. ------------ and this is what is in the onCollision function.. Runtimer:addEvevntListener("collsion", stopTimer)

this might not be perfect code because i wrote in in 30 seconds… but its a start… 

Thanks for any help

To check if the timer exists use:

if myTimer then --do stuff end

So i dont do this?

local function timerCheck() if myTimer == "began" then --do stuff end end

what is i want to check if and when it began or ended and i want to add an event listener to it…?

If you store a handle to your timer, you can always check to make sure it’s not nil. The other thing is set your own variable when you start the timer and then check it later when you need it.

Rob

Lol sorry Rob but im a visual learner so when you explain things my mind just explodes haha can you get my code and check it out? change something to make it work?

This is an opportunity to expand your abilities.

local myTimer

local function doSomething()

     myTimer = nil   – done with the timer

end

if myTimer ~= nil then

    – timer is still active

end

myTimer = timer.performWithDelay( 1000, doSomething )

when i remove timers i cancel them first. niling a timer or a transition don’t remove it’s action if it’s already running. you need to cancel it’s action first to avoid errors:

if myTimer then

     timer.cancel(myTimer)

     myTimer=nil

end

True, if it’s a reoccuring timer, you would need to cancel it, but if the timer is a one timer, it self-cancels.

To check if the timer exists use:

if myTimer then --do stuff end

So i dont do this?

local function timerCheck() if myTimer == "began" then --do stuff end end

what is i want to check if and when it began or ended and i want to add an event listener to it…?

If you store a handle to your timer, you can always check to make sure it’s not nil. The other thing is set your own variable when you start the timer and then check it later when you need it.

Rob

Lol sorry Rob but im a visual learner so when you explain things my mind just explodes haha can you get my code and check it out? change something to make it work?

This is an opportunity to expand your abilities.

local myTimer

local function doSomething()

     myTimer = nil   – done with the timer

end

if myTimer ~= nil then

    – timer is still active

end

myTimer = timer.performWithDelay( 1000, doSomething )

when i remove timers i cancel them first. niling a timer or a transition don’t remove it’s action if it’s already running. you need to cancel it’s action first to avoid errors:

if myTimer then

     timer.cancel(myTimer)

     myTimer=nil

end

True, if it’s a reoccuring timer, you would need to cancel it, but if the timer is a one timer, it self-cancels.