Yield inside another function

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

It seems, when a function that yields (func1) is called inside another function (func2), yield stops only func1, and func2 just goes on without waiting for func1 to resume. How do I stop func2 using yield in func1, or maybe other way?

extends Button

signal resume_func1

func _ready():
	func2()

func func2():
    print(1)
    func1()
    print(4)

func func1():
    print(2)
    yield(self, "resume_func1")
    print(3)

func _on_Button_button_down():
	emit_signal("resume_func1")

This goes 124(button)3, but what I want is 12(button)34.

:bust_in_silhouette: Reply From: volzhs

yield waits for a signal as you know.
so, need to a signal for waiting.

signal custom_signal

func func2():
    print(1)
    func1()
    yield(self, "custom_signal") // This waits for "custom_signal" signal.
    print(4)

func func1():
    print(2)
    yield(Node, "signal")
    print(3)
    emit_signal("custom_signal") // This emits "custom_signal" signal, so `func2()` will continue

this will work as you expect.

Ah, so I need to yield twice. Thank you I got it!

Haseb | 2017-10-23 00:38