Skip to reading
GDScript Programming & Godot

28. Subscribe to PCA events

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView illustrations
Code example
func on_scene_loaded(event: Dictionary = {}) -> void:
    if str(event.get("sceneId", "")) != "lab":
        return
    Log("The workshop is ready.")
Code example
func on_trigger_entered(event: Dictionary = {}) -> void:
    if str(event.get("triggerId", "")) == "welcome_trigger":
        Log("The player crossed the welcome area.")

Write the matching on_* function, then check the corresponding Event Functions box in the GDScript editor. Writing a handler name alone is not a subscription to every runtime broadcast.

The event argument is a Dictionary. OnSceneLoaded provides the room ID; trigger events provide triggerId and related context. Filter a broad listener before doing local work. A local door response and a global interaction listener can both run, so guard one-time rewards.

Figure 10. The subscriptions tell PCA which event functions to dispatch to this record.

on_global_ready is a special startup call for a global native record that defines it. You do not need a second ordinary subscription merely to initialize that global instance.

Page 37 of 378Permalink
Go to page