{{htmlmetatags>metatag-robots=() metatag-title=(ADD | ugBASIC User Manual) metatag-keywords=(ugBASIC,Commodore 64,Commodore PLUS/4,ZX Spectrum) metatag-description=(Manual page for ADD) metatag-media-og:image=(:ugbasic:logo-ugbasic-fb.png) metatag-og:title=(ADD | ugBASIC User Manual) metatag-og:description=(Manual page for ADD) }} ====== ugBASIC User Manual ====== ===== ADD ✓ ===== ===== SYNTAX ===== ADD var, expr [, min TO max] [CLAMP] ==== PURPOSE ==== 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. ==== EXAMPLE ==== ADD y,10 ADD x,42,1 TO 100 CLAMP See also the following example files: * ''[[https://github.com/spotlessmind1975/ugbasic/tree/main/examples/maths_fast_02.bas|maths_fast_02.bas]]'' ==== ABBREVIATION ==== Ad ==== AVAILABLE ON ==== * * Atari (400/800) * Atari XL/XE * Commodore 128 (MOS 8502) * Commodore 128 (Zilog Z80) * Commodore 64 * Commodore 64+REU * TRS-80 Color Computer * TRS-80 Color Computer 3 * ColecoVision * Amstrad CPC 664 * Dragon 32 * Dragon 64 * Thomson MO5 * Thomson MO5 * Olivetti Prodest PC128 * Commodore PLUS/4 * SEGA SC-3000 * SEGA SG-1000 * * VG-5000 * Commodore VIC-20 * ZX Spectrum 48 ==== ANY PROBLEM? ==== If you have encountered a problem using this command, if you think there is a bug or the explanation is unclear, please [[https://github.com/spotlessmind1975/ugbasic/issues/new?title=ISSUE ON ADD|open an issue]] for this keyword on GitHub. Thank you!===== POWERED BY ===== [[:ugbasic:user:index|{{ :ugbasic:user:logo-ugbasic.png?nolink&600 |}}]]