In compile-time the constant gets replaced with the value associated with it, e.g., a number or a string literal. Contrary to a variable the value of the constant cannot be changed in run-time.
Constants are declared either statically or dynamically. Each edit mode can load static constant definitions from a file using the
<constants>parameter in the
modes.xml. Dynamic declarations get created in the script code with the syntax outlined below.
To declare a new constant in the code, use the
const <constant name> = <constant value>
A constant name is any allowed identifier (a combination of letters, numbers and
_). There are names reserved by the compiler that cannot be used, such as
compiler.ini). A constant value might be a number (also a model identifier or a label); a string literal; a variable (also a class property); another constant.
const x = 5
You can declare multiple constants separating each declaration with a comma like this:
const a = 1, b = 2, c = 3
If you prefer to have each declaration on its own line, conclude them in a
a = 1
b = 2
c = 3
More complex example:
MoneyRequired = 30
PlayerMoney = $PLAYER_CHAR.Money
PlayerMoney > MoneyRequired
PlayerMoney += -1
During compilation the constant
MoneyRequiredgets replaced with the number