Skip to reading
GDScript Programming & Godot

CreateVariable()

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

Create Variable

Create a variable only when that name is absent. It is an initializer, so calling it again does not reset an existing value.

Source table from CreateVariable(), page 90
Option key / fieldMeaning and inputDefault
Variable ID nameText.Blank
Type variableTypeChoose: string, boolean, number, array."string"
Initial Value valueA value of the type required by the selected variable, operation or property.Blank

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

Code example
await CreateVariable({"name": "powered", "variableType": "boolean", "value": true})

In use. Create visits with a numeric value of 0, then increment it on room entry. Define long-lived puzzle variables in the Variable Designer so their starting values are easy to find. The variableType field is descriptive; do not rely on it to convert bad input.

Page 90 of 378Permalink
Go to page