How can I remove all timers that I lunched with timer.performWithDelay?
what I’ve tried:
for id in pairs(timer) do
print("timer: " … id)
if id ~= nil then
timer.cancel( id )
end
end
How can I remove all timers that I lunched with timer.performWithDelay?
what I’ve tried:
for id in pairs(timer) do
print("timer: " … id)
if id ~= nil then
timer.cancel( id )
end
end
I don’t think there is a function to cancel them all automatically.
Instead I would add each timer to a single table, and then loop through that and cancel them all.
local myTimers = {} local function cancelAllTimers() for k, v in pairs(myTimers) do timer.cancel(v) end end myTimers[#myTimers+1] = timer.performWithDelay(2000, someFunction, 30) myTimers[#myTimers+1] = timer.performWithDelay(4000, someOtherFunction, 15) myTimers[#myTimers+1] = timer.performWithDelay(6000, myLastFunction, 10)
This way you can have a single table per scene, or a module that is accessible globally to cancel all timers in every scene.
I don’t think there is a function to cancel them all automatically.
Instead I would add each timer to a single table, and then loop through that and cancel them all.
local myTimers = {} local function cancelAllTimers() for k, v in pairs(myTimers) do timer.cancel(v) end end myTimers[#myTimers+1] = timer.performWithDelay(2000, someFunction, 30) myTimers[#myTimers+1] = timer.performWithDelay(4000, someOtherFunction, 15) myTimers[#myTimers+1] = timer.performWithDelay(6000, myLastFunction, 10)
This way you can have a single table per scene, or a module that is accessible globally to cancel all timers in every scene.