-
-
Save AndersonFirmino/ab2caeddc8bdde337fec0bc90e657fec to your computer and use it in GitHub Desktop.
Godot Quick Tips 01: The create_timer() helper for waiting X seconds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Available only in the 2.2 legacy branch and posterior versions | |
func _ready(): | |
# The old way: | |
print("HELLO") # Code before the yield | |
# Setting up the yield: | |
var t = Timer.new() # Create a new Timer node | |
t.set_wait_time(5.5) # Set the wait time | |
add_child(t) # Add it to the node tree as the direct child | |
t.start() # Start it | |
yield(t, "timeout") # Finally, make the script stop with the yield | |
print("WORLD") # Code that will be exectued after the yield | |
print("=====") | |
# The optional new way: | |
print("HELLO AGAIN!") # Code before the yield | |
# Setting up the yield with the new function 'create_timer()': | |
yield(get_tree().create_timer(5.5),"timeout") | |
print("WORLD") # Code that will be exectued after the yield |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment