Run your first Lua record
LESSON 01
Give the game a line of dialogue and give yourself a way to tell whether the script ran.
Open a test project. Select the Lua workspace, create a script and give it the unique ID first_lua.
Leave Enabled on and Global Script off. Replace the entire source with the record below.
local Script = {}function Script.run(context)
Log("The archive bell rang.")
await(ShowMessage({ text = "Someone is still in the archive.",
duration = 1.0 }))
return 42
endreturn ScriptChoose Validate, then Apply Changes and save the project. Start Test Scene or Play. Use Run Script
against the running preview, or attach the script to an interaction. Look for the log line and the
on-screen message. The number 42 is available to a caller that captures the return value.
Read the four moving parts#
Script is a local table. The function declaration puts run in that table. PCA calls it and supplies the
caller context. The final return gives the whole table to PCA. Put other exported functions above
that last line. A top-level return of 42 would hand PCA a number where it needs a module.
Each boxed Lua record in the lessons can replace an entire record unless labeled as a fragment. Use a
fresh ID per lesson to keep earlier exercises available.
