Attack system with stamina.Couldnt update variable value in timeout signal.

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

New to Godot as well as programming, trying to create a simple stamina system.

var points = 1

func _physics_process(_delta):
    if.Input.is_action_pressed("attack")  && points == 1:
    attack.set_frame(0)
    attack.play()

func _attack_on_animation_finished():
    points = points - 1
    timer.start()

func _on_timer_timeout():
    points = points + 1

The idea is simple, i want to only attack when there is a point left. Its like a stamina and should be consumed if an attack is made. So i reduced the point when the attack is made and started a timer of 1 sec. when the timer runs out the points is back. but the variable is not updating. please help. is there anyother good idea for a stamina system or what am i doing wrong??

:bust_in_silhouette: Reply From: Inces

It looks valid to me. You should try to debug it by printing. Print something in every of these functions and You will see which function is not called. Are You sure points don’t go above 1 ?

For systems revolving around one variable it is good to use setter functions. With them You will be able to apply repetitive behavior every time this variable is attempted to be changed, without resorting to multiple functions.