Skip to reading
Lua Scripting

Write a line the player can see

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 PDF page

FIRST SCRIPT

This is the complete first_lua record. Read it from top to bottom. To see it run in your game, enter it in the new record’s code box.

Code example
local Script = {}
Code example
function Script.run(context)
    Log("The archive bell rang.")
    await(ShowMessage({ text = "Someone is still in the archive.",
                        duration = 1.0 }))
    return 42
end
Code example
return Script

Read it from top to bottom#

Source table from Write a line the player can see, page 5
local Script = {}Make an empty table. Think of it as a folder for the things this script can do.
function Script.runDefine the job PCA3D starts when you run the record. The parentheses receive information about what started it.
Log(...)Write a line for the game’s author to see in the output.
ShowMessage(...)Give the player a message. The braces hold settings, including the text and its duration in seconds.
return 42Send the number 42 back to whoever called run. The player sees the message. A caller can use the number.
end / return ScriptEnd the function, then hand the table of functions back to PCA3D.

Keep the straight quotation marks when typing code. The two words in ShowMessage have capital S and M.

Lua scripting   /   Illustrated guide                                                          W05
Page 5 of 133Permalink
Go to page