Sanny Builder
Search…
Constants
A constant is an identifier with a predefined value. Contrary to a variable the value of the constant can not be changed in run-time. In compile-time the constant gets replaced with the value associated with it. The value of the constant can be numeric (numbers, model names or labels) and string (string literals), and contain an expression.
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.

Syntax

To declare a new constant in the code use the CONST..END construct:
CONST <constant name> = <constant value> END
A constant name is any allowed identifier (a combination of letters, numbers and _). There are names reserved by the compiler that can not be used, such as Continue, Break, And, etc (see 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.
1
var
2
$PLAYER_CHAR: Player
3
end
4
5
const
6
MoneyRequired = 30
7
PlayerMoney = $PLAYER_CHAR.Money
8
end
9
10
if
11
PlayerMoney > MoneyRequired
12
then
13
PlayerMoney += -1
14
end
Copied!
During compilation the constant MoneyRequired gets replaced with the number 30 and PlayerMoney with $PLAYER_CHAR.Money
When the Language service is enabled, a list of constants gets displayed after pressing Ctrl+Space.

Limitations

You can use constants anywhere except the case:
1
const
2
VarName = $Var
3
IndexName = 25
4
end
5
VarName[IndexName] = 0
Copied!
To compile such expression, you must write the opcode, for example:
1
0004: VarName[IndexName] = 0
Copied!
Also there are some limitations with using an expression as the constant value.
Last modified 3mo ago
Copy link