Skip to content

Instantly share code, notes, and snippets.

@zetashift
Created August 13, 2018 00:30
Show Gist options
  • Save zetashift/529f2e6c82b17a7e1bfa3c13f2f73e56 to your computer and use it in GitHub Desktop.
Save zetashift/529f2e6c82b17a7e1bfa3c13f2f73e56 to your computer and use it in GitHub Desktop.
Simple Nim godot example
# taken from: https://github.com/pragmagic/godot-nim/issues/17#issuecomment-399192271
import godot, node, input
gdobj MyNode of Node:
method init*() =
addUserSignal("my_signal") # Declare on init. If need to connect this signal to other nodes, should be done in code
method ready*() =
connect("my_signal", self, "_on_my_signal_emitted")
method process*(delta: float64) =
if isActionPressed("my_action"):
discard callDeferred("deferred_emit") # As we are not interested in the values returned by this function, this should be discarded
proc deferredEmit*() {.gdExport.} = # deferredEmit is interpreted as deferred_emit by the API
emitSignal("my_signal")
method onMySignalEmitted*()= # By not using .gdExport., the API will read "_on_my_signal_emitted"
print("I got a deferred signal")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment