Refresh all already started timer from a node ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By quizzcode

hey guys !
Im working on a tower defense and im working on the “frost tower”.
The frost tower apply a slow to the unit and not stack. It works great !

But, when the unit is hit again by a frost tower, i want to update the current timer.
I used set_wait_time(effect_time) but it doesn’t work…

I was wondering if one of you had an idea on how to adapt my script to make it work ?

Here is my function effect()

if effect_frost == 0:
		#Set the speed minus effect_amount %
		var slow_amount = (speed * effect_amount) / 100 # make that # into a number
		speed -= slow_amount #update the speed of unit
		effect_frost = 1 #This unit is now frosted.
		#Start timer to turn it off when it's done.
		$Timer_frost.connect("timeout",self,"slow_effect_done", [slow_amount])
		$Timer_frost.set_wait_time(effect_time+1)
		$Timer_frost.start()

	else: #He is already frost, let's just restart the timer with effect_time.
		$Timer_frost.set_wait_time(effect_time) # trying to update the current timer.
		print("Already frosted") 
		print($Timer_frost.get_time_left())

Oh and on timeout slow_effect_done, i stop the timer and set the effect_frost to 0.
any idea why/how to update the current timer ?

Thx !

:bust_in_silhouette: Reply From: njamster

The wait_time is only used when the timer is started. Changing it while the timer already runs won’t do anything. What you actually want to change is time_left. However, you cannot set this option directly, but have to call start() with an (optional) argument specifying the new time instead:

# ...
else:
    $Timer_frost.start(effect_time)
    # ...

Hey ! Thanks for your reply.
I see ! Timeleft makes total sense.

	$Timer_frost.set_wait_time(effect_time)
		$Timer_frost.start()

Lovely ! Thanks !

quizzcode | 2020-05-20 09:21