I am calling a function using timer.performWithDelay. As you can see the iterations is set to 0 so that it will continue to run.
timer.performWithDelay (3000, myroutine,0)
I also have a button bar that contains 3 buttons, each one changes the scene.
When the routine starts and I click a button it continues to iterate through the routine without stopping.
So my question, I know there is a timer.cancel but I’m not sure where that function goes. Would the timer.cancel go in the onBtnPress function?
Or should I try to use the approach outlined in the document whereby I check for onBtnPress event and cancel within myroutine?
local t = {}
function t:timer( event )
local count = event.count
print( “Table listener called " … count … " time(s)” )
if count >= 3 then
timer.cancel( event.source ) – after 3rd invocation, cancel timer
end
end
– Register to call t’s timer method an infinite number of times
timer.performWithDelay( 1000, t, 0 )