25. Events: respond when the game changes
global visits = 0when game starts
log("A new play session has started.")
endwhen room lab loads
visits += 1
log("Room visits: " + str(visits))
endwhen player enters trigger welcome_trigger
log("The player crossed the welcome area.")
endA when block is an event handler. The runtime finds matching handlers in enabled PCA Script records and supplies the event context. You do not need to call run() to make a normal when room lab loads handler listen. Be careful about also calling the same work from a room action list; that can run it twice.
Built-in event phrases can filter a room, trigger, character, dialogue or media asset. The full event reference gives the exact phrase and payload. A handler runs for the event actually emitted; inventing an English phrase does not create an engine hook.
Figure 9. PCA event handlers are declared in the source. Simulate Event can help test a handler without repeating a full playthrough.
A plain function named on_scene_loaded is not the normal PCA event declaration. Use when room lab
loads, or the exact-name event form in the reference. Native GDScript/Lua/BASIC subscription controls have their own conventions.
