Topic was automatically imported from the old Question2Answer platform.
Asked By
ReddBear
When I try to call function using yield(foo(), "completed"), runtime error appears: First argument of yield() is not of type object, but example from here shows that it should work:
It may also be of interest to those running into this issue for the first time, that a function that can sometimes yield or not can be handled using the GDScriptFunctionState that returns.
If the function doesn’t yield it will return either null or its given value. This can be checked to safely handle yielding for its completion when the function does yield.
With the code below, experimenting with different delay parameters will show this off.
extends Node2D
func _ready():
var result = my_func()
if(result is GDScriptFunctionState and result.is_valid()):
print("awaiting my_func()")
yield(result, "completed")
print("done")
func my_func(delay = 1.0):
if(delay > 0.0):
yield(get_tree().create_timer(delay), "timeout")