Stop a performWithDelay function

Hi guys, i have a performWithDelay function that runs 10 times.

I want to make it like, if the level ends, the function is stopped and doesnt work anymore, unless you play the level again.

Basically, i don’t know what to do to stop a performWithDelay wich is already in progress.

If it’s impossible, is there a workaround for this case?

Thanks in advance.

Assign it to a variable:

myTimer = timer.performWithDelay(…)

Then do
timer.cancel(myTimer)
Wherever you need to cancel it

Wow, I totally forgot about the cancel function, didn’t use performWithDelay in a long time,

Thanks JonPM!

Assign it to a variable:

myTimer = timer.performWithDelay(…)

Then do
timer.cancel(myTimer)
Wherever you need to cancel it

Wow, I totally forgot about the cancel function, didn’t use performWithDelay in a long time,

Thanks JonPM!