Skip to reading
The Variable Designer

18. Create a variable during play

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

Most puzzle facts are easiest to define in Variable Designer before the game starts. That gives them a known type, a starting value and an entry in reference selectors. Create Variable is useful when a script or action must introduce a key during play.

Source table from 18. Create a variable during play, page 31
Create Variable fieldExample
Variable IDruntime_note
Typestring
Initial Value"First value" in the action-list value field

Create Variable only creates the key if it does not already exist. Running it again with another initial value leaves the existing current value alone. Use Set Variable when you intend to replace that value.

Code example
await CreateVariable({
    "name": "runtime_note",
    "variableType": "string",
    "value": "First value"
})
Code example
await SetVariable({
    "name": "runtime_note", "value": "Replacement"
})

What it does and does not add#

The new key belongs to the running game. It does not create a new authoring record in Variable Designer, so do not expect it to appear there after the test. It can be included in a saved game because saves keep the current runtime variables.

The Type choice is not a universal conversion step. Supply the correct kind of Initial Value yourself. In code, use true for a Boolean, a number for a Number and an actual Array for an Array.

Source table from 18. Create a variable during play, page 31
During the testResult
Create runtime_note = "First value"The missing key is created.
Create it again = "Second value"It remains "First value".
Set it = "Replacement"It becomes "Replacement".

If a variable is central to the game and other designers should select it, define it in Variable Designer. Runtime-created keys are better kept for deliberate dynamic data than for working around a misspelt ID.

Page 31 of 37Permalink
Go to page