How to use yield with callv?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Gus G

Hi, I’m writing a game with a series of events that need to happen, and I’m storing them in a list of lists. Each list has a string (the function name) and its arguments (in a list), and I’m iterating through and using callv. Most of these “actions” take some time to complete (tweens, etc.) and I’m using yield in each function to wait until it’s done, but when I use it in conjunction with callv like I described it just ignores the yield and does everything at once.

func exampleAction():
    var sceneNode = preload("res://Scenes/Lens Flare.tscn").instance()
    add_child(sceneNode)
    yield(sceneNode, "tree_exited")    

func _ready():
    var actions = [
    ["exampleAction", []]
    ]

    print(actions)
	for action in actions:
		print(typeof(action[1]))
		callv(action[0], action[1])

If there’s another way I could structure my project, that would also be considered.

:bust_in_silhouette: Reply From: Dlean Jeans

You need a yield call inside the for loop, and there happens to be a way to do just that:

for action in actions:
	yield(callv(action[0], action[1]), 'completed')

You can do that with any functions and it will wait for the functions or the yields inside them to complete before moving on.