6. Operators

What are operators?

Operators are signs that represent specific arithmetical or binary operations. DestinyScript supports 9 operators. The set operator is neutral, because it can be used with each data type. Furthermore there are 5 arithmetical operators (addition, subtraction, multiplication, Division and Modulo). The addition ist something special, because it can be used for the concatenation of strings, too. At last there are 3 binary operators (AND, OR and XOR).

Set

Description

The simpliest operator is the set operator we already know. With this operator it is possible to assign a value to a destination directly. This operator can only be used at the beginning of a command. This operator works with each data type. The equality sign (=) is used for this operator.

Signs

SignsBeginning?
=yes

Example

1
2
$
v[1] = 1

Addition

Description

You can add two values with the addition operator. This operator can be used at the beginning and in the rear part of a command. If you apply an addition at the beginning of a command the rear part of the command will be processed as if it is written in parentheses. If this operator is used with strings then the values will be concatenated. Switches can't be added. The plus sign (+) is used for this operator.

Signs

SignsBeginning?
+no
+=yes

Example

1
2
3
4
5
$
v[1] = 1 + 10 + 100;
v[1] += 20;
a[1] = "Joe";
a[2] = "Hello " + a[1]
The variable no. 1 whould be 131 at the end and the string no. 2 whould be "Hello Joe".
Information
If you use the addition operator to concatenate strings then you may only use strings. For example this command whould raise an error:
a[1] = "Number equals " + v[1]
Instead all data types must be converted to strings first if you concatenate them. This command whould be valid:
a[1] = "Number equals " + Convert.String(v[1])
The Convert object is used here.

Subtraction

Example

You can subtract two values with the subtraction operator. This operator can be used at the beginning and in the rear part of a command. If you apply a subtraction at the beginning of a command the rear part of the command will be processed as if it is written in parentheses. Strings and switches can't be subtracted. The minus sign (-) is used for this operator.

Signs

SignsBeginning?
-no
-=yes

Example

1
2
3
$
v[1] = 50 - 7;
v[1] -= 9
The variable no. 1 whould be 34 at the end.

Multiplication

Description

You can multiply two values with the multiplication operator. This operator can be used at the beginning and in the rear part of a command. If you apply a multiplication at the beginning of a command the rear part of the command will be processed as if it is written in parentheses. Strings and switches can't be multiplied. The multiplication sign (*) is used for this operator.

Signs

SignsBeginning?
*no
*=yes

Example

1
2
3
$
v[1] = 7 * 3;
v[1] *= 3
The variable no. 1 whould be 63 at the end.

Division

Description

You can divide two values with the division operator. This operator can be used at the beginning and in the rear part of a command. If you apply a division at the beginning of a command the rear part of the command will be processed as if it is written in parentheses. Strings and switches can't be divided. If you divide through zero an error will occur. The division slash (/) is used for this operator.

Signs

SignsBeginning?
/no
/=yes

Example

1
2
3
$
v[1] = 100 / 10;
v[1] /= 2
The variable no. 1 whould be 5 at the end.

Modulo

Description

In the modulo operation the left value will be divided by the right value (integer division) and the remainder will be returned (this is the part of the left number, which whould be required to build the decimal part of the result). This operation can be used at the beginning and in the rear part of a command. If you apply a modulo operation at the beginning of a command the rear part of the command will be processed as if it is written in parentheses. Strings and switches can't be divided. If you divide through zero an error will occur. The percent sign (%) is used for this operation.

Signs

SignsBeginning?
%no
%=yes

Example

1
2
3
4
$
v[1] = 100 % 3;
v[2] = 99;
v[2] %= 10
The variable no. 1 whould be 1 at the end and variable no. 2 whould be 9.

AND operator

Description

You can apply a binary AND operation with two values via the AND operator (this means that every bit is AND operated). This operation can be used at the beginning and in the rear part of a command. If you apply an AND operation at the beginning of a command the rear part of the command will be processed as if it is written in parentheses. Strings, switches and doubles can't be AND operated. The ampersand sign (&) is used for this operation.

Sings

SingsBeginning?
&no
&=yes

Example

1
2
3
4
$
v[1] = 100 & 7;
v[2] = 31;
v[2] &= 255
The variable no. 1 whould be 4 at the end and variable no. 2 whould be 31.

OR operation

Description

You can apply a binary OR operation with two values via the OR operator (this means that every bit is OR operated). This operation can be used at the beginning and in the rear part of a command. If you apply an OR operation at the beginning of a command the rear part of the command will be processed as if it is written in parentheses. Strings, switches and doubles can't be OR operated. The pipe sign ( | ) is used for this operation.

Signs

SignsBeginning?
|no
|=yes

Example

1
2
3
4
$
v[1] = 7 | 3;
v[2] = 1;
v[2] |= 100
The variable no. 1 whould be 7 at the end and variable no. 2 whould be 101.

XOR operation

Description

You can apply a binary EXCLUSIVE OR operation (XOR) with two values via the XOR operator (this means that every bit is XOR operated). This operation can be used at the beginning and in the rear part of a command. If you apply a XOR operation at the beginning of a command the rear part of the command will be processed as if it is written in parentheses. Strings, switches and doubles can't be XOR operated. The circumflex sign (^) is used for this operation.

Signs

SignsBeginning?
^no
^=yes

Example

1
2
3
4
$
v[1] = 27 ^ 13;
v[2] = 1;
v[2] ^= 3
The variable no. 1 whould be 22 at the end and variable no. 2 whould be 2.