Operators are used to build expressions. Expressions in RSL are similar to expression in most high level computer languages and standard algebra.
Operators are symbols used to perform mathematical and logical manipulations
of values and variables. The term
used to describe the values and variables that operators manipulate is
"operands". The
combination of operands and one or more operators is called an expression.
Expressions can themselves be used as operands, allowing arbitrarily complex
expressions. Mathematical and logical operators may be used together in a single
expression.
The order in which operators are applied is called precedence. Operator precedence in RSL follows that of standard scientific calculators and most computer languages. Operators with equal precedence are applied in a left-to-right order. Precedence is one continuous spectrum across both mathematical and logical operators. Brackets ( ) may be used to manually change operator precedence.
Mathematical Operators
In RSL trigonometric functions are operators rather than commands. This is actually somewhat inconsistent because they have the same syntax as commands. While inconsistent, it is also convenient to be able to perform trigonometric operations in expressions.
The addition operator is the only mathematical operator that works with string operands. When used with strings, the addition operator creates a new string by appending the second operand to the first.
| Description | Usage | Operand type | Precedence |
| cosine | cos( operand ) | numeric | 1 |
| sine | sin( operand ) | numeric | 1 |
| tangent | tan( operand ) | numeric | 1 |
| arccosine | acos( operand ) | numeric [-1 to 1] | 1 |
| arcsine | asin( operand ) | numeric [-1 to 1] | 1 |
| arctangent | atan( operand ) | numeric | 1 |
| arctangent of x/y | atan2( x, y ) | numeric | 1 |
| exponentiation (power) | operand1 ^ operand2 | numeric | 2 |
| multiplication | operand1 * operand2 | numeric | 3 |
| division | operand1 / operand2 | numeric | 3 |
| modulus | operand1 % operand2 | numeric | 3 |
| addition | operand1 + operand2 | numeric, string | 4 |
| subtraction | operand1 - operand2 | numeric | 4 |
To find the nth root of a value, raise the value to the power of 1/n. The example below finds the square root (which is the 2nd root) of 16, adding 4 to the print log.
Note that the first parameter to atan2 is the x coordinate and the second
parameter is the y coordinate. Most other programming languages take the y
coordinate first followed by the x coordinate. Robot Battle is reversed because
of the orientation of the x and y axes.
Logical Operators
Logic operators may be used with both numeric and string operands. When a string is tested for true or false, the string evaluates to true if it has at least one character and false if it is empty. When strings are compared using ordering operators such as less than, a case sensitive lexicographic (alphabetical) comparison is made. For case insensitive string comparisons, use the stricmp command.
Some logic operators have two forms. Both are shown below.
| Description | Usage | Operand type | Precedence |
| less than | operand1 < operand2 | numeric, string | 5 |
| less than or equal to | operand1 <= operand2 | numeric, string | 5 |
| greater than | operand1 > operand2 | numeric, string | 5 |
| greater than or equal to | operand1 >= operand2 | numeric, string | 5 |
| equal to | operand1 == operand2 | numeric, string | 6 |
| not equal to | operand1
!=
operand2 operand1 <> operand2 |
numeric, string | 6 |
| logical and | operand1
&&
operand2 operand1 and operand2 |
numeric, string | 7 |
| logical or | operand1
||
operand2 operand1 or operand2 |
numeric, string | 8 |
See Also