0 votes

yield(get_tree.create_timer(#sec),"timeout!") is short and nice but it returns error every frame if executable is gone after executed.

I'm either interested in a way how to make yield() stop looking for executable after it's gone, or a simple alternative to that without much complication. I honestly made a method that works, but it's long and hefty. Interested in short way.

Also trying to understand Time node. How can I shortly make an alternative to yield() with Time node? "Wait x seconds, do something".

Thank you for your time! Much appreciated!

Godot version 3.2.3
in Engine by (305 points)

2 Answers

0 votes

You can yield for anything that is an object.
You can wait for nodes function until it is completed with return, You can also wait till some node emits a chosen signal. These are usually very handy for controlling flow of various game phases. In the same way You can wait for your timer node to emit signal "timeout", which every Timer node has built in. FOr this :

var T = ( reference to your timer here )
yield(T,"timeout")

However there is no sollution to avoid error when yielding instance is gone. It is not crashing error anyways. However You can use TImers "timeout" signal normally, by connecting it to Your node and resolving it onTimertimeout(), just like all signals ever

by (1,121 points)

Been trying an odd solution. Added AudioStreamPlayer with silent audio file with desired length, and used finished() signal to implement stuff which works without an error, but adds up unnecessary data (audio file).

Can you please guide me with an example? Before I used to do it this way:

yield(get_tree.create_timer(5),"timeout")
get_tree().reload_current_scene()

It worked but with errors. How would you do it with Timer?

Your main goal is to avoid error when executable is gone ?
If so You should use basic signal properties, You should learn about them in tutorial and documentation, they are more basic than yielding

Basically both yield() and signal connected nodes "listen" to built in signals. If You pick any node in editor, on the right of Godot UI You can change inspector Tab to see its possible signals. If You click Timer node You will see a lot of signals like on-ready, exit tree, and so on, and one of them is "timeout".

If You did it with AudioStream You should do it exactly the same with Timer node. Connect it, and instead of "finished" use "timeout" signal. Then set time and start the Timer. All methods for setting up Timer are in Godot help. I am not sure what kind of example You are looking for

Thank you for your help! Much appreciated.

0 votes

Another addition to the previous answer is adding the timer node in the editor. I think it is much more effective and manageable since it has many methods that you can use and is not susceptible to bugs like you've mentioned

by (380 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.