The second function will stop executing for 1 second, but before the time is out it will go back to the first function, is there anyway to stop executing the called function without going back to the calling one ?
Yes, in the latest versions at least, there is a completed signal you can use for functions, so just yield the first function as well, until it is finished. The results can also be stored in a variable and checked following the yield if needed.
When yield is called in second function it implicitly returns GDScriptFunctionState object which can emit completed signal once it’s done executing, so the first function can be rewritten like this:
func _first_function():
var state = _second_function()
yield(state, "completed")
The first approach is more useful If you’re not sure whether the second function is going to return GDScriptFunctionState or it’s supposed to return some other object or value, so you can do this instead:
func _first_function():
var result
var ret = _second_function()
if ret is GDScriptFunctionState:
# yielding to signal to get the return value from second function
var state = ret
ret = yield(state, "completed")
else:
result = ret
return result
So the second approach is used when the second function returns a value, Thank you!, i got it.