Ok so im going to try and explain this problem as best as I can because its going to be the death of me. I have a function that creates a certain number of timers based on how many times the user touches a button(pressCount1). The delay of the timers is based on when the user touches the button, my issue is say the user touches the button 15 times. When the function is called, it creates 15 timers all set with increasing delays. But I want to be able to cancel all of these timers at any point. How can I do this??
function tracks1()
for i = 1 , pressCount1 do
trackTimer = timer.performWithDelay(pressTimes1[i], play1)
end
end
Let me show an example. Consider a button that plays a sound clip(BEEP!). The user presses it 5 times.
----- The # of times a user pressed the button
pressCount1 = 5
----- this holds all the times (in seconds) at which the button was pressed.(first press is always 0)
pressTimes{}= "0, 1.53, 2.34, 5.64, 8.99"
So when I run the function this is what is created:
trackTimer = timer.performWithDelay(0, play1)
trackTimer = timer.performWithDelay(1.53, play1)
trackTimer = timer.performWithDelay(2.34, play1)
trackTimer = timer.performWithDelay(5.64, play1)
trackTimer = timer.performWithDelay(8.99, play1)
----play1 just plays the sound from the button, so effectively this creates a sort of recording effect. Mimicking back the users pattern of touches.
My problem is if these timers are invoked, and then say after 2 seconds (the first two timers have already fired) and at this point I want to STOP all of the rest( the ones that fire at 2.34, 5.64, and 8.99), How can I do this?
I tried timer.cancel(trackTimer) but that will only stop the last one that I created (trackTimer = timer.performWithDelay(8.99, play1)).
Geez I hope this isn't as confusing as it seems. This has kept me stagnent on my project for a long time. Is there a way to maybe put all of those timers into a group, and then just remove the group or something?