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.
ADD var, expr [, min TO max] [CLAMP]
Join BASIC 10Liner Contest with ugBASIC!
An interesting competition is held at the beginning of each year: the
BASIC 10Liner Contest.
It is possible to use ugBASIC to participate in the next
"BASIC10Liner" competition, in the following categories:
ADD ↔ Ad
If you have found a problem with this keyword, if you think there is a bug or, more
simply, you would like it to be improved, open an issue for this example on GitHub.
Thank you!
open an issue
BACK TO KEYWORDS