Skip to reading
Lua Scripting

Remember a yes or no

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

GAME VARIABLES

Has the player met the stationmaster? Has someone opened the archive? Each question has just two answers. A Boolean variable is a natural fit.

The inspector shows a Boolean named archive_open. The unchecked Initial Boolean Value means it starts false.

Set the starting value#

In Variable Designer, give the variable an ID. Select Boolean for Value Type. Leave Leave Blank At Start unchecked when the game should know the answer from the first frame. The Initial Boolean Value checkbox then sets that answer.

Change it during play#

Code example
await(SetVariable({ name = "archive_open", value = true }))

This fragment goes inside a function. Once the game runs this line, another script can ask about the same variable by ID.

Read it somewhere else#

Code example
if IfVariable("archive_open", true) then
    Log("The bolt is open.")
end

Keep IDs consistent in both places. A player can see the word “Archive” on a door even when the underlying variable has a completely different name.

Lua scripting   /   Illustrated guide                                                          W09
Page 9 of 133Permalink
Go to page