0 votes

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.

in Engine by (47 points)
edited by

1 Answer

+2 votes

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.

by (9,742 points)

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.