Godot Version
4.3
Question
Sorry if this is a stupid question or if I misuse the terminology; I’m pretty new to Godot.
I’m aware that I can make a wait function with await get_tree().create_timer(float).timeout
, but I wanted to use it as a global function (it is a singleton) in Global.gd, so I could simply use Global.wait(float) anywhere else in the same scene. I made this code in Global.gd:
func wait(timex):
. print("So timex equals to: ", timex)
. timex = timex * 1.0
. print("Now it is ", timex)
. await get_tree().create_timer(timex).timeout
. print("The await command is supposed to have worked")
And in this other script I had:
Global.wait(2.0)
[more code]
However, as soon as the function is called, the rest of the code is executed. I have noted, though, that the function is indeed called, but the wait function only works in Global.gs (the last print message is sent 2 seconds later). How can I do a global function so that I can call it anywhere in the scene and make the calling code wait until the global code stops?
Thank you