Trouble with yield() statement

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By vonflyhighace2
:warning: Old Version Published before Godot 3 was released.

I can’t seem to understand how to use the Yield function. I’ve tried following the docs but they just seem to confuse me even more. Nothing seem to work when following the examples in the Docs :(… can someone please explain with some useful examples. Possibly using standard and signals/callbacks. I’ve also posted code sample of what i’m trying to accomplish.

  var test = null
    
func myFunc():
test = TriggerFX()
test.resume
print("Darn")
        
func TriggerFX():
print("Hello")
yield()
print("World")

Your code is wrong in many ways that, to me it’s not clear what you are trying to do. Try explaining it with words with a self-contained (pseudo-)code maybe.

Check the docs also (which explicitly mentions that it is the function that yields returns the function state, on which you can call resume, not the other way around).

Also, in case you’re going to use it with signals, current implementation of yield doesn’t work as advertised in the docs: you can yield only from a top-level function. See this issue for details.

dragoon | 2016-04-05 04:07

OK. I think I’m starting to get the hang of how things run. Is GDScript synchronous or asynchronous when it comes to execution of methods? I’m coming from a C#/JavaScript background so some things are a bit different dealing with GDScript.

vonflyhighace2 | 2016-04-05 23:27