What happens when a script runs?
On this page
START HERE
Suppose a player examines a bell. The game needs to know what to show the player and when to show it. A Lua script can describe that response in a few lines.
The player sees the sentence inside ShowMessage. The editor can also log a separate line for the author.
Who starts the script?#
You can start it yourself with Run Script in the Lua Designer. In a game, a button, a hotspot or an event can start it. The same code can run from any of those places.
What does PCA3D look for?#
function Script.run(context)
Log("The archive bell rang.")
endRead this as “When someone runs this record, write this line to the output.” run is the function name. context is information PCA3D sends along, such as which interaction started the script.
Where does the code live?#
Open your game in PCA3D and select the Lua workspace. Each record has a name for you and an ID for the engine. The next two pages show the editor and a complete record, including the lines that go above and below the function.
A box marked fragment shows part of a script. A complete record includes everything from the first local declaration through the final return.
Lua scripting / Illustrated guide W03
