Difference between revisions of "Addn"
(Created page with "The '''addn''' command adds a numerical value to a variable. == Syntax == <BLOCKQUOTE> addn(var vA, byt B); vA = vA + B; vA += B; </BLOCKQUOTE> == Rema...") |
m (→Remarks) |
||
(3 intermediate revisions by the same user not shown) | |||
Line 8: | Line 8: | ||
</BLOCKQUOTE> | </BLOCKQUOTE> | ||
== Remarks == | == Remarks == | ||
− | Because [[variable | + | Because [[variable]]s are 8 bit unsigned numbers, if the result of the addition exceeds 255, the result 'wraps around'. For example, if v50 currently equals 200, the statement: |
+ | |||
+ | <CODE>addn(v50, 100);</code> | ||
+ | |||
+ | will result in a value for v50 of 44 (200 + 100 = 300; 300 - 256 = 44). This can be represented mathematically as vA = (vA + B) % 0x100. | ||
+ | |||
If the value of B is 1, [[WinAGI]] will use the '''[[increment]]''' command instead of '''addn''' if you use the alternate syntax (i.e. vA = vA + 1 or vA += 1). To force the compiler to use '''addn''', use the full form: addn(vA, 1). This is important because the '''[[increment]]''' command does not wrap around like the '''addn''' command. | If the value of B is 1, [[WinAGI]] will use the '''[[increment]]''' command instead of '''addn''' if you use the alternate syntax (i.e. vA = vA + 1 or vA += 1). To force the compiler to use '''addn''', use the full form: addn(vA, 1). This is important because the '''[[increment]]''' command does not wrap around like the '''addn''' command. | ||
+ | |||
== Possible Errors == | == Possible Errors == | ||
None. | None. | ||
Line 17: | Line 23: | ||
<div class="CodeBlockHeader">Code:</div> | <div class="CodeBlockHeader">Code:</div> | ||
<syntaxhighlight lang="agi"> | <syntaxhighlight lang="agi"> | ||
− | v50 = | + | v50 = 150; |
addn(v50, 75); [ v50 now equals 225 | addn(v50, 75); [ v50 now equals 225 | ||
v50 = v50 + 75; [ v50 now equals 44 (300 - 256) | v50 = v50 + 75; [ v50 now equals 44 (300 - 256) | ||
Line 38: | Line 44: | ||
'''[[addv]]'''<br /> | '''[[addv]]'''<br /> | ||
'''[[increment]]'''<br /> | '''[[increment]]'''<br /> | ||
+ | |||
+ | [[Category:Commands]] |
Latest revision as of 21:45, 23 April 2019
The addn command adds a numerical value to a variable.
Syntax
Remarks
Because variables are 8 bit unsigned numbers, if the result of the addition exceeds 255, the result 'wraps around'. For example, if v50 currently equals 200, the statement:
addn(v50, 100);
will result in a value for v50 of 44 (200 + 100 = 300; 300 - 256 = 44). This can be represented mathematically as vA = (vA + B) % 0x100.
If the value of B is 1, WinAGI will use the increment command instead of addn if you use the alternate syntax (i.e. vA = vA + 1 or vA += 1). To force the compiler to use addn, use the full form: addn(vA, 1). This is important because the increment command does not wrap around like the addn command.
Possible Errors
None.
Example
<syntaxhighlight lang="agi"> v50 = 150; addn(v50, 75); [ v50 now equals 225 v50 = v50 + 75; [ v50 now equals 44 (300 - 256) v50 += 75; [ v50 now equals 119 </syntaxhighlight>
Technical Information
Required Interpreter Version: | Available in all AGI versions. |
Byte-Code Value: | 5 (0x05 hex) |