Can't stop timer.performwithdelay

Hello guys, I’m using a timer.performwithdelay to display some images but when I leave the main game scene I can’t avoid it continuing displaying those. I need to stop the timer.performwithdelay and clear the images from the screen. I’ve tried with timer.pause(myfunction(myparams)) but it doesn’t work.

That’s the code:

local powerup\_start1=timer.performWithDelay( 700, function() powerup(player2, 2, blueSegmentTransition, blueX, blueY, lenblueX); end) local powerup\_start2=timer.performWithDelay( 700, function() powerup(player1, 1, redSegmentTransition, redX, redY, lenredX); end)

How do I stop these? And how do I clear the images?

Hi @mimmi.ferrini,

A timer must be paused (or cancelled) using the handle  (variable) you assigned it to. So, the proper usage would be like this:

[lua]

timer.pause( powerup_start1 )

– or…

timer.cancel( powerup_start1 )

[/lua]

Hope this helps,

Brent

Ok, I’ve tried this but it doesn’t work since, I’ve just realised, the powerup function is recursive so if I stop the timer.performwithdelay I’m just stopping the first istance of the recursion. How can I fix this? Maybe making it recall itself with the handler instead of the mere timer.performwithdelay(powerup) so that doing the timer.pause I’ll stop every istance?

what do you mean by “clear the images”?

To stop every instance you will need to store every instance and then cancel them.  Or maybe have a variable that defines if you should “do something” and if this is false then don’t “do something”

I solved this by calling each new istance by the generic handler and then using timer.pause(handler). Thank you for the tip!

Hi @mimmi.ferrini,

A timer must be paused (or cancelled) using the handle  (variable) you assigned it to. So, the proper usage would be like this:

[lua]

timer.pause( powerup_start1 )

– or…

timer.cancel( powerup_start1 )

[/lua]

Hope this helps,

Brent

Ok, I’ve tried this but it doesn’t work since, I’ve just realised, the powerup function is recursive so if I stop the timer.performwithdelay I’m just stopping the first istance of the recursion. How can I fix this? Maybe making it recall itself with the handler instead of the mere timer.performwithdelay(powerup) so that doing the timer.pause I’ll stop every istance?

what do you mean by “clear the images”?

To stop every instance you will need to store every instance and then cancel them.  Or maybe have a variable that defines if you should “do something” and if this is false then don’t “do something”

I solved this by calling each new istance by the generic handler and then using timer.pause(handler). Thank you for the tip!