Skip to reading
PCA Script Programming

25. Events: respond when the game changes

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
global visits = 0
Code example
when game starts
    log("A new play session has started.")
end
Code example
when room lab loads
    visits += 1
    log("Room visits: " + str(visits))
end
Code example
when player enters trigger welcome_trigger
    log("The player crossed the welcome area.")
end

A 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.

Page 33 of 357Permalink
Go to page