Timer not callable

Godot Version

4.1.2

Question

So im simply trying to start a timer but i always end up with an error message that the node was not found [quote=“spiele-maus, post:1, topic:56523, full:true”]

Godot Version

4.1.2

Question

So im simply trying to start a timer but i always end up with an error message that the node was not found

E 0:00:11:0050 SaveData.gd:85 @ timer_restart(): Node not found: “Timer” (relative to “/root/SaveData”).
<C+±Fehler> Method/function failed. Returning: nullptr
<C+±Quelle> scene/main/node.cpp:1626 @ get_node()
SaveData.gd:85 @ timer_restart()
torch.gd:14 @ _on_area_2d_body_entered()
[/quote]

E 0:00:11:0050 SaveData.gd:85 @ timer_restart(): Node not found: “Timer” (relative to “/root/SaveData”).
<C+±Fehler> Method/function failed. Returning: nullptr
<C+±Quelle> scene/main/node.cpp:1626 @ get_node()
SaveData.gd:85 @ timer_restart()
torch.gd:14 @ _on_area_2d_body_entered()

does the code queue free the timer at any point

1 Like

what exactly do you mean?

does your code delete the timer
because it looks like it only happens when you restart the timer

1 Like

no it does not, as the the point is that it will only be restet as it is game over when it ends. but i dont see why that would be the issue. afterall the issue that it is not found in the first place, even so its there

Have you enabled one shot in your timer?

yes i have

Ok, then you can try this -

func restart(time):
print(“start”)
await get_tree().create_timer(time).timeout
print(“end”)

The thing is that this is not quite how it should work, as this creates a new timer every time the function is triggered. but what I want is just 1 timer that gets reset every time the function is called, as the goal of the game is to prevent the timer from reaching zero

My last idea, just create a timer inside the script like var timer = Timer.new()

like this or what

var timer = Timer.new()

func timer_restart (time):
timer.start(time)

func _process(delta):
if timer.timeout :
print (“end”)

because this just constantly gives me “end” messenges.

timer.timeout is a signal, you can’t use it in an if statement, you need to connect to it, see here

Hey spiele-maus, Your codes is wrong, here is the right codes, I have tested it and it running properly :-

extends Control

var timer = Timer.new()

func _ready():
timer.timeout.connect(_on_timer_timeout)
get_tree().current_scene.add_child(timer)
timer_restart(0.5)

func timer_restart(time):
timer.start(time)
#It will be loop, if you don`t want, enabled one shot of the timer

func _on_timer_timeout():
print(“end”)

Thanks

2 Likes