29. Custom events and Godot signals
func on_custom_event(event: Dictionary = {}) -> void:
if str(event.get("reason", "")) == "signal_powered":
Log("The lamp has power.")func run() -> void:
await EmitEvent("OnCustomEvent", {"reason": "signal_powered"})This uses the standard OnCustomEvent route and a reason field. A custom exact event name is also possible, but a native handler needs a route that maps to a real method. For a shared native listener, the standard hook plus a discriminator is straightforward.
Godot signals are a different mechanism: a particular object emits a typed signal to connected Callables. Use PCA events for adventure-wide notifications and Godot signals for relationships between your own nodes. The Godot signal chapter shows the full connection pattern.
Do not broadcast the same notification from its own handler without a guard. Set saved state before emitting a completion event, and avoid circular chains of listeners.
