Gamevar operators: Difference between revisions
Jump to navigation
Jump to search
Helixhorned (talk | contribs) add some general info; and to div and mod. Make % sign undefined, see http://en.wikipedia.org/wiki/Modulo_operation C89 vs. C99. |
Helixhorned (talk | contribs) add examples for the bitwise operators. |
||
Line 54: | Line 54: | ||
| | | | ||
|bitwise AND | |bitwise AND | ||
|The bits in the result are set only if they were set in both of the values being operated on. | |The bits in the result are set only if they were set in both of the values being operated on. Ex.:<br/> | ||
01001010 AND<br/> | |||
11110100 is<br/> | |||
01000000 | |||
|- | |- | ||
|or | |or | ||
Line 60: | Line 63: | ||
| | | | ||
|bitwise OR | |bitwise OR | ||
|The bits in the result are set only if they were set in either of the values being operated on. | |The bits in the result are set only if they were set in either of the values being operated on. Ex.:<br/> | ||
01001010 OR<br/> | |||
11110100 is<br/> | |||
11111110 | |||
|- | |- | ||
|xor | |xor | ||
Line 66: | Line 72: | ||
| | | | ||
|bitwise XOR | |bitwise XOR | ||
|The bits in the result are set if only one of the values being operated on has those bits set. | |The bits in the result are set if only one of the values being operated on has those bits set. Ex.:<br/> | ||
01001010 XOR<br/> | |||
11110100 is<br/> | |||
10111110 | |||
|} | |} | ||
Revision as of 10:00, 18 April 2012
<operator>var <gamevar> <value>
<operator>varvar <gamevar> <value>
Gamevar operators are commands that perform various mathematical and bitwise logical operations on gamevars. The first argument must be a writable gamevar and is taken as the destination as well and the first operand (2-address code).
For example:
setvar temp 3 // assigns a value of 1 to the gamevar temp. addvar temp 1 // adds 1 to temp, causing its value to become 2. mulvar temp 2 // multiplies temp by 2, causing its value to become 4.
Operator | C/C++ | Math | Description | Notes | |
---|---|---|---|---|---|
set | =
|
= | assignment | ||
add | +
|
+ | addition | ||
sub | -
|
– | subtraction | ||
mul | *
|
× | multiplication | ||
div | /
|
÷ | division with rounding toward 0 | Ensure that <value> does not equal 0 at any time. | |
mod | %
|
modulo, remainder | Ensure that <value> does not equal 0 at any time; It is undefined whether the sign of the result follows the divisor or the dividend (for now). | ||
and | &
|
bitwise AND | The bits in the result are set only if they were set in both of the values being operated on. Ex.: 01001010 AND | ||
or | |
|
bitwise OR | The bits in the result are set only if they were set in either of the values being operated on. Ex.: 01001010 OR | ||
xor | ^
|
bitwise XOR | The bits in the result are set if only one of the values being operated on has those bits set. Ex.: 01001010 XOR |
Commands with an additional "var" suffix take gamevars rather than constants or defined labels for their inputs. As an alternate short form, "varvar" can be dropped from these commands; for example ife serves an an alias for ifvarvare.