Skip to content
AEOWUN
Docs Menu

Variables

Keep a value and use it later.

Set a value

Use const for a value you do not need to reassign:

const starting_gold = 100
debug.log(starting_gold)

For a number you want to change, declare it with a type first:

score: number = 0
score += 10
debug.log(score)

This prints 10. You can declare other mutable types too:

health: number = 100
name: string = "Ada"
ready: bool = true

Constants

Use const when the variable should not be assigned again.

const max_health = 100

A constant basket can still have its contents changed. Use basket.freeze() to make its contents read-only.

Scope

Top-level variables are available to functions and event handlers in the same script. Function parameters and local variables belong to their function. Separate Module files keep separate state. Actor-attached Modules also keep state for each Actor. See Modules.

No value

Use nil for no value. Check a lookup result before reading its properties. See Finding Objects.