Skip to reading
Lua Scripting

Let entering a room run a script

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

GAME EVENTS

You can ask PCA3D to call your code when something happens. Here, every arrival adds one to a running count and writes the room ID to the output.

In room_arrivals, Keep global instance alive retains the count for this play session. OnSceneLoaded subscribes the record to room arrivals.

Code example
local Script = {}
local arrivals = 0
Code example
function Script.on_scene_loaded(event)
    arrivals = arrivals + 1
    Log("Arrival " .. arrivals .. " in " .. tostring(event.sceneId))
end
Code example
function Script.run(context)
    return arrivals
end
Code example
return Script

The first arrival starts at zero and adds one. On entering the second room, the same script instance still holds one, so the next arrival becomes two. Checking an event and defining its matching function are both part of the hookup.

In the capture, the room IDs were lab and roof. The output read Arrival 1 in lab, then Arrival 2 in roof. Use a PCA variable such as archive_open for progress a player needs after loading a game.

Lua scripting   /   Illustrated guide                                                          W13
Page 13 of 133Permalink
Go to page