Operators
Operators are special symbols that tell a RapidScript program to perform a specific mathematical or logical operation.
Arithmetic
These arithmetic operators require both operands to be numeric types (except for the +
operator).
Operator | Name | Usage |
---|---|---|
| addition |
|
| subtraction, unary negative |
|
| multiplication |
|
| division |
|
| modulo |
|
Notes
The addition operator can also take operands that are strings. If either operand is a string, the returned value will be a concatenation of both operands as a string (numeric types will be converted to their string equivalent, e.g.
4
becomes"4"
). For example:"hello" + "there"
returns"hello there"
.The division operator will return its quotient as a double. If the quotient is assigned to an integer variable, the fractional values will be discarded.
The modulo operator performs an integer division, then returns the remainder. For example,
10 % 3
returns1
.The unary negative sign operator returns the additive inverse of the given number.
Assignment
Assignment operators assign a new value to the variable on the left-hand side of the operator. The left-hand side must be a variable, while the right-hand side may be a literal value or a variable.
Assignment operators containing an arithmetic operator will modify the variable using the given value and arithmetic operation. The operation will be performed using the variable as the left-hand term and the given value as the right-hand term. The result of the operation will be assigned to the variable. The equivalent statements are shown in the table below.
Operator | Usage | Equivalent |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Terms on the right-hand side of the =
operator are evaluated before the left-hand side. In the statement var = var + value
, var + value
will use the original value of var
before a new value is assigned to it.
Comparison and Relation
The comparison and relation operators form expressions that return a bool
value representing whether or not the expression is true.
Operator | Description | Usage |
---|---|---|
| Equal to |
|
| Not equal to |
|
| Greater than |
|
| Less than |
|
| Greater than or equal to |
|
| Less than or equal to |
|
Notes
The comparison and relation operators all operate on numeric types. The
==
and!=
operators can also takebool
types. None of these operators can takestring
(orvoid
) types.
Logical
The logical operators form logical expressions, and can only operate on bool
values.
Operator | Description | Usage |
---|---|---|
| AND |
|
| OR |
|
| XOR |
|
| NOT |
|
Notes
The logical XOR (also known as exclusive OR) operator returns
true
if and only if one of its operands istrue
. If both aretrue
orfalse
, then the exclusive OR returnsfalse
. The OR operator on the other hand will returntrue
if either or both operands aretrue
.The logical NOT returns the complement of the given operand.
!true
returnsfalse
, and!false
returnstrue
.The logical AND returns
true
if and only if both operands evaluate totrue
.
Increment and Decrement
Increment and decrement operations must operate on a variable. They alter the variable's value, increasing or decreasing it by one. They may also be applied as a prefix or a suffix, which changes when the increment/decrement occurs.
Operator | Description | Usage |
---|---|---|
| Increment |
|
| Decrement |
|
Notes
When used as a prefix (known as a pre-increment or pre-decrement), the operator increases (or decreases) the value of the variable by one, then returns the altered value.
When used as a suffix (known as a post-increment or post-decrement), the operator increases (or decreases) the value of the variable by one but returns the original, unaltered value.
Bitwise
Bitwise operators operate on the bits in the binary representation of numeric types.
Operator | Usage | |
---|---|---|
| Bitwise AND |
|
| Bitwise OR |
|
Notes:
Assigning the value returned from these operators to a data type that is too small to contain all of the bits will truncate the most significant bits until the value fits. For example, doing a bitwise operation with two
int64
values then assigning the result to anint16
variable will only keep the first 16 bits of the result.
Last updated