Godot Version
4.21
Question
I’m looking at GDScript…
From my perspective of dealing with Lua, coroutines were absolutely necessary.
I found the ‘yield’ keyword…
'A function with that keyword becomes a coroutine…
When calling yield, a coroutine object is returned, and by calling the ‘resume’ function on the coroutine object, it is possible to proceed after ‘yield’.
It was similar to the coroutine seen in Lua and was very easy.
func my_func():
print(“Start”)
yield()
print(“Resume”)
func_ready():
var y = my_func()
# Function state saved in ‘y’.
print(“Waiting to resume”)
y.resume()
# ‘y’ resumed and is now an invalid state.
[Users can control coroutines very simply by looking at the code]
So, when using Lua, I gave each game object a coroutine and ran it like a micro thread…
The problem is that this ‘yield’ keyword is only supported up to version 3.5 of GDScript.
In GDScript, ‘await’ was added instead of ‘yield’ keyword…
It was very difficult to understand.
It has to be used with signal…
I’m not sure how to use it like ‘yield’ and ‘resume’.
Please tell me how to write it like ‘yield’