Is there a wait function to godot

You can’t just put it in a function like wait() and then call it.
Yield starts a co-routine. But you call it like a normal method. So it just starts the co-routine, but your _ready does not wait for completion of it.

This is a working code snippet:

extends Node

func _ready():
	print("{hour}:{second}".format(OS.get_datetime()))
	yield(wait(2), "completed")
	print("{hour}:{second}".format(OS.get_datetime()))

func wait(seconds):
	yield(get_tree().create_timer(seconds), "timeout")

To be honest I would not put it in a method. I would just use yield(get_tree().create_timer(seconds), "timeout") wherever you need it.

1 Like

What winston said, but also do you have a specific situation/problem? The official Docs and numerous tutorials on youtube are the place for theoreticals/learning general concepts. Otherwise we will go on for infinite amount of time.

Forums are far better for solving specific problems/crashes/etc. So if you have real app with code that isn’t working but you need to make work, just reference that example.

1 Like

i tried to not use the function itself and now it works thank you alot

1 Like

You marked this as being answered but out of curiosity, what are you waiting for?
Are you waiting for an animation to finish, or for keyboard input or something else?

1 Like

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