Timer appears to be getting faster

Godot Version

4.2.2

Question

this is my code, it’s used whenever a character in my turn based battle system uses a skill, which for now happens automatically without any user input. i’m aware that starting and stopping a preexisting timer is better practice, but that didn’t work at all for some reason as it looked as if the timer isn’t even there.

$BattleHud/TextBar/Label.text = "%s used %s" % [user.character_name,skill.skill_name]
await get_tree().create_timer(1,false).timeout

#do damage
damage = (skill.damage + user.strength + user.level*0.3 -
 (character.resilience + character.level*0.3))
character.hp -= damage
$BattleHud/TextBar/Label.text = "did %s damage" % damage

user.mp -= skill.mp_cost

if character.status == enums.status_effect.NONE:
	character.status = skill.status

update_hud()
await get_tree().create_timer(1,false).timeout

the first call goes as expected, but after that it gets faster and faster and in no time at all it’s as if the timer didn’t exist.

Is this part of a loop? Are you creating a timer every frame?

yes (well it was until i tried to do a workaround and accidentally ended up coding myself into an even bigger mess)

Then the code is waiting on a new timer each frame, thus only delaying it by one second rather than halting for one second. Could this code be moved to a connection? Like when a button is pressed or using the _input function override?

yep, i’ve already done so, sorry for wasting your time with something i ended up solving independently

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.