[Godot 4.0] Timer Funcition Not Working/Starting

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

I’m making a top down shooter, based on some older tutorials, i tried adding a timer, so the character may not constantly shoot without a cooldown.

So i have created a timer node, and conected it to the character, but it simply does not work.

> if Input.is_action_pressed("Shoot") and Global.criacao_no_pai != null:
> > Global.instance_node(projectile, global_position, Global.criacao_no_pai)
> > reloaded = false
> > $reload_time.start()

func _on_reload_time_timeout() -> void:
> reloaded = true

The timer node is called “reload_time”, i also have the the variable for reloaded as

var reloaded = true
:bust_in_silhouette: Reply From: jgodfrey

Are you sure you’re getting inside the if block where you start the timer? Add a print statement just before that $reload_time.start() is called and make sure you see it when expected.

Likewise, maybe add a print statement inside that _on_reload_time_timeout() method so it’s obvious when it gets called.

Also, have you actually wired the timer to that timeout method?

Beyond that, what’s the wait_time for the timer set to? Maybe it’s much longer than expected.

:bust_in_silhouette: Reply From: aidave

You’re not checking the reloaded variable

Add if reloaded: before shooting