Skip to reading
GDScript Programming & Godot

Gameplay: Variables, rewards and reusable logic

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

Keep puzzle facts in variables, then use a visual or text script when a decision is needed. A list is an ordered set of instructions; it does not gain a branch just because an action returns false.

SetVariable()#

Set Variable

Assign a value to a runtime game variable. This replaces its previous value and can create the runtime entry if it does not exist.

Source table from Gameplay: Variables, rewards and reusable logic, page 89
Option key / fieldMeaning and inputDefault
Variable nameChoose a game variable name. Custom values are accepted.Blank
Value valueA value of the type required by the selected variable, operation or property.true

Timing. Waits for the runtime routine to return; no further completion wait is promised by this schema.

Code example
await SetVariable({"name": "powered", "value": true})

In use. Set powered to true when the lever is used. Use a Boolean value, not the text "true". In the room/object inspector, choose Change Variable with Operation set to Set instead.

Page 89 of 378Permalink
Go to page