Skip to content

Instantly share code, notes, and snippets.

@cbscribe
Forked from brunosxs/create_timer.gd
Last active February 14, 2017 19:16
Show Gist options
  • Save cbscribe/41a785cbbe3a72edf9962dac3746e79c to your computer and use it in GitHub Desktop.
Save cbscribe/41a785cbbe3a72edf9962dac3746e79c to your computer and use it in GitHub Desktop.
Godot Quick Tips 01: The create_timer() helper for waiting X seconds
# 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