0 votes

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 setwaittime(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 sloweffectdone, i stop the timer and set the effect_frost to 0.
any idea why/how to update the current timer ?

Thx !

in Engine by (184 points)

1 Answer

+1 vote
Best answer

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)
    # ...
by (10,608 points)
selected by

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

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

Lovely ! Thanks !

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.