Available on: all targets

ADD

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.

SYNTAX

 ADD var, expr [, min TO max] [CLAMP]


Legend
  • id : identifier
  • type : datatype
  • v : value
  • "..." : string
  • [...] : optional

EXAMPLE

 ADD y,10
 ADD x,42,1 TO 100 CLAMP


Used in:

ABBREVIATION: Ad

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:

  • PUR-120 - A game in 10 lines of max 120 characters (w/abbrev.)
  • EXTREME-256 - A game in 10 lines of max 256 characters (w/abbrev.)
  • SCHAU - Any program in 10 lines of max 256 characters (w/abbrev.)
In order to reduce space you can use this abbreviation for this instruction:

ADD ↔ Ad

Any problem?

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