The AGS scripting engine supports the following operators in expressions. They are listed
in order of precedence, with the most tightly bound at the top of the list.
WARNING: When using operators of equal precedence, AGS by default evaluates them
right-to-left. So, the expression a = 5 - 4 - 2; evaluates as a = 5 - (4 - 2);
which is not what you might expect. Always use parenthesis to make it clear what you want.
The "Left-to-right operator precedence" option on the General Settings pane allows you to
control this behaviour.
\bf{
Operator Description Example
}
! NOT if (!a)
* Multiply a = b * c;
/ Divide a = b / c;
% Remainder a = b % c;
+ Add a = b + c;
- Subtract a = b - c;
<< Bitwise Left Shift a = b << c;
(advanced users only)
>> Bitwise Right Shift a = b >> c;
(advanced users only)
& Bitwise AND a = b & c;
(advanced users only)
| Bitwise OR a = b | c;
(advanced users only)
^ Bitwise XOR a = b ^ c;
(advanced users only)
== Is equal to if (a == b)
!= Is not equal to if (a != b)
> Is greater than if (a > b)
< Is less than if (a < b)
>= Is greater than or equal if (a >= b)
<= Is less than or equal if (a <= b)
&& Logical AND if (a && b)
|| Logical OR if (a || b)
This order of precedence allows expressions such as the following to evaluate as expected:
if (!a & b < 4)
which will execute the 'if' block if a is 0 and b is less than 4.
However, it is always good practice to use parenthesis to group expressions. It's much
more readable to script the above expression like this:
if ((!a) & (b < 4))
|