ADD var, expr [, min TO max] [CLAMP]
The ADD
statement is used to increment the value of a numeric variable by
a specified amount. In other words, it is like adding one number to another.
The basic syntax take the var
to which you want
to add a value and the expr
as the expression you want to add to the variable.
The full syntax takes also two additional parameters: min
and max
,
that are the minimum and maximum value that the variable can take after
the increment. In other words, the var
is incremented, but its value is
“squeezed” between min
and max
. If the result of the addition
had been greater than max
, the level would be put to min
. Otherwise,
if the var
si less than min
, the variable will be set to max
.
It is possible to “clamp” the value of var
instead of turn around
the limits. By using the CLAMP
keyword, you can change the behaviour:
var
will be assigned to min
if a value is lesser than min
and
to max
if a value is greater than max
.
The purpose of this second syntax is to prevent a variable from taking invalid value for your program. It can also help to simulating real-world systems: for example, in a game you can limit a character's life between 0 and 100. This instruction can also help to create special effects: you can create bouncing or wrapping effects, by making a variable “bounce” between two values. In videogames, the typical use is to limit the maximum score in a game, or to preventing a difficulty level from exceeding a certain value.
Ad
If you have encountered a problem using this command, if you think there is a bug or the explanation is unclear, please open an issue for this keyword on GitHub. Thank you!