Skip to content

Instantly share code, notes, and snippets.

@swarnimarun
Last active June 5, 2019 16:34
Show Gist options
  • Save swarnimarun/a9322fcd35164469903bba4f3beddb5c to your computer and use it in GitHub Desktop.
Save swarnimarun/a9322fcd35164469903bba4f3beddb5c to your computer and use it in GitHub Desktop.
Using Yield GDScript for a Notifier Model
extends Node
## NOTIFIER MODEL
class MyNotifier extends Object:
signal poke
func poke():
# this can even take arguments if you want to pass some
emit_signal("poke", "hello", "hi")
var obj_notify = MyNotifier.new() # create an object that will broadcast messages
var time = 0
func notify_me():
return obj_notify
func do_something():
print("doing something")
print(yield(notify_me(), "poke")) # returns an array
# this is much easier compared to hooking up signals
print("back to doing something")
func do_something_else():
print("doing something else")
yield(notify_me(), "poke")
print("back to doing something else")
func _ready():
do_something()
do_something_else()
func _process(delta):
# poke every 2 seconds
time += delta
if time > 2:
obj_notify.poke()
time = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment