Count speed variable

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

I made a condition for the regeneration of the health of my character. But it happens very quickly.

func _process(delta):
if food > 95:
	yield(get_tree().create_timer(3.0), "timeout")
	health += 1
if health > 100:
	health = 100

I tried to change the value to a smaller one

func _process(delta):
if food > 95:
	yield(get_tree().create_timer(3.0), "timeout")
	health += 0.01
if health > 100:
	health = 100

But that is not what I need
I would be grateful if you indicate where I was wrong

:bust_in_silhouette: Reply From: Blackthorn

If I understand your question correctly, I think your problem is that the part in the if-statement ‘food > 95’ is executed several times (I don’t think the timer prevents the game from calling the process function again). Try to do something like

if food > 95:
    food = 95 #In order to prevent the program from jumping to this part again
    yield(get_tree().create_timer(3.0), "timeout")
    health += 1
if health > 100:
    health = 100
:bust_in_silhouette: Reply From: Calinou

Instead of health += 1, use health += delta to add 1 HP every second. This is because delta corresponds to the time passed in seconds since the last rendered frame.