Looking for a short alternative to yield(get_tree.create_timer(#),"timeout!")

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

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!

:bust_in_silhouette: Reply From: Inces

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 )

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 on_Timer_timeout(), just like all signals ever

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:


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

Suleymanov | 2021-04-12 16:34

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

Inces | 2021-04-12 20:05

Thank you for your help! Much appreciated.

Suleymanov | 2021-04-12 20:08

:bust_in_silhouette: Reply From: Mrpaolosarino

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