spacer graphic
spacer graphic
Montage of games AGS Logo
spacer graphic

 

spacer graphic
Menu
spacer graphic Home
About
News
Features
Download AGS
spacer graphic Games 
Games main page
Award Winners
Picks of the month
Short games
Medium length games
Full length games
In Production
Hints & Tips
Community
Forums
AGSers World Map
Member websites
Chat
Resources
Tutorials
FAQ
Knowledge Base
Downloads
Links
AGS-related links
* AGS Manual
  * Scripting
    * Script language keywords

Operators

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))


User comments and notes
There are currently no user comments on this page.
The user comment facility is currently disabled.