0 votes

For example, say I have this function:

var event_x_happened = false

func proceed_only_if_event_x_already_happened()
    if not event_x_happened:
        print("waiting for it...")
        yield(self, "event_x")
        event_x_happened = true
    print("now it happened for sure - continue")

Is it guaranteed that the signal event_x will not be emitted on the line
print("waiting for it...")
and hence will get missed out by the line
yield(self, "event_x")
thus causing a deadlock?

Godot version 3.2.3
in Engine by (132 points)

If your code isn't multithreaded, while the GDScript VM is processing proceed_only_if_event_x_already_happened() it can't emit the signal the yield is waiting for, because it will only return from the function when reaching the yield (and eventually call your emit_signal() after that).

Thank you. That's what I wanted to know - that once a func starts executing, no other code will be executed before it finishes (other than the cases of yield or multithreading)

1 Answer

0 votes

It depends only how You are planning on checking this event.
signal will never be missed because of other lines, it is independent from lenght of code, it all happens too fast.

But if You somehow emit "event" before whole function is started, then it will be deadlocked. You have to time it properly.

by (1,544 points)
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.