restart my timer node ???

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

Alright bare with me it’s a little tricky:
I have a progress bar called “Guardbar” basically a block mechanic for blocking attacks,
when the Guardbar is visible it is blocking and when it is not visible it is not blocking, I have an Enemy “Evil Plum” doing the damage to the Guardbar which works, When the Guard bar is damaged a timer node starts() for 8 seconds, after the 8 seconds the Guardbar regenerates to 100%, what I’m trying to do is if the Guard bar is attacked for a 2nd time whilst the timer is counting I want to stop the timer() and restart it to take into consideration the new damage I have just accumulated and only when the Guardbar is depleted to 0% will it play the Timer() node un interrupted for 8 seconds.
extends Control

onready var healthbar = $HealthBar
onready var guardbar = $GuardBar
onready var guardtimer = $Timer
var max_guard = 100

func ready():
guardbar.visible = false

func _physics_process(_delta):
if Input.is_action_pressed(“Guard”):
guardbar.visible = true

if Input.is_action_just_released("Guard"):
	guardbar.visible = false

func die():

func _on_Evilplum_damage(value):
if guardbar.visible == true:
guardbar.value -= value
# if struck again timer stops() and restarts

	healthbar.value -= value
if guardbar.value <= 0:
if healthbar.value <= 0:

func guard_depleted():

func _on_Timer_timeout():
guardbar.value += max_guard

:bust_in_silhouette: Reply From: dewcked

set guard delay variable:

var guarddelay = 8 # you can change this also

make initializer function:

func init_guard_timer():
    guardtimer.wait_time = guarddelay

now you can call anywhere if you want to initialize guard delay.


Cheers I literally just lowered the value of the attack and it was doing what I wanted it to do, I feel like such a dumbass sometimes, it was looping through the code and every time I got attacked again it would restart the timer to 8 seconds but thank you for the comment i’ll definitely be able to implement it some where.

markelliot_94 | 2021-11-25 09:36

Actually, you don’t need depleted() method. as you can ignore it when guard is 100% broken like this code below:

func onEvilplum_damage(int val):
    if guardbar.visible == true and guardbar.value != 0:
        guardbar.value = guardbar.value - value if guardbar.value > 0 else 0
        healthbar.value = healthbar.value - val if healthbar.value > val or 0
    if healthbar.value == 0:

dewcked | 2021-11-25 10:16