Skip to reading
GDScript Programming & Godot

ChangeVariable()

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

Change Variable

Set or modify a variable using set, arithmetic, append or toggle. The operation determines how Value is used.

Source table from ChangeVariable(), page 91
Option key / fieldMeaning and inputDefault
Variable nameChoose a game variable name.Blank
Operation operationChoose: set, add, subtract, multiply, divide, append, toggle."set"
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 ChangeVariable({"name": "powered", "operation": "set", "value": true})

In use. Choose score, Add, 5 for a five-point reward. Toggle suits a repeatable switch; Set is safer when an event may run twice. Keep arithmetic numeric and avoid dividing by zero.

AddScore()#

Add Score

Increase the runtime variable named score by the given integer amount.

Source table from ChangeVariable(), page 91
Option key / fieldMeaning and inputDefault
Amount amountNumber of points to add to score.1

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

Code example
await AddScore({"amount": 1})

In use. Award 5 after collecting a unique key. This action does not remember that the key was already collected. Put it behind the same one-time condition as the reward. In a native inspector, Change Variable / score / Add is the direct equivalent.

Page 91 of 378Permalink
Go to page