Skip to reading
Lua Scripting

What happens when a script runs?

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
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?#

Code example
function Script.run(context)
    Log("The archive bell rang.")
end

Read 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
Page 3 of 133Permalink
Go to page