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.