How to cancel timer from another function?

Hello,

I need to call timer.cancel(id) from another function. How do I get the ID of the timer? The only example I see is to cancel it in its listener event. I am setting a timer for 30 seconds for the max to record an audio. If the user completes before then I need to cancel the timer.

Thanks,

Warren

Well you need to store the timer ID in a variable that’s in scope to the function where you’re going to use it.  Probably the easiest way is to declare it ‘local’ at the top of the module where both functions exist, i.e.

local timerID

local function createTimer()

     timerID = timer.performWithDelay(1000, doSomething)

end

local function killTimer()

    timer.cancel(timerID)

end

Well you need to store the timer ID in a variable that’s in scope to the function where you’re going to use it.  Probably the easiest way is to declare it ‘local’ at the top of the module where both functions exist, i.e.

local timerID

local function createTimer()

     timerID = timer.performWithDelay(1000, doSomething)

end

local function killTimer()

    timer.cancel(timerID)

end