Scripting: Operators – Arma Reforger
Lou Montana (talk | contribs) m (Text replacement - "\{\{Wikipedia *\| *([a-zA-Z0-9_#':%]+) *\| *([a-zA-Z0-9_#':% ]+) *\}\}" to "{{Link|https://en.wikipedia.org/wiki/$1|$2}}") |
Lou Montana (talk | contribs) (Add ++i & --i, Change h4 font, Add xxx[i] note & example) |
||
Line 8: | Line 8: | ||
=== Assignment === | === Assignment === | ||
<div style="font-family: monospace"> | |||
==== {{=}} ==== | ==== {{=}} ==== | ||
</div> | |||
The "assign operator sets the righthand value to the lefthand variable. | The "assign operator sets the righthand value to the lefthand variable. | ||
<enforce> | <enforce> | ||
Line 15: | Line 17: | ||
{{Feature|important|This operator is '''NOT''' an equality check. For this, see {{Link|#{{=}}{{=}}}}.}} | {{Feature|important|This operator is '''NOT''' an equality check. For this, see {{Link|#{{=}}{{=}}}}.}} | ||
<div style="font-family: monospace"> | |||
==== ++ ==== | ==== ++ ==== | ||
The increment operator adds 1 to the provided numerical variable. It only applies to int and float values. | </div> | ||
The increment (or post-increment) operator adds 1 to the provided numerical variable. It only applies to int and float values. | |||
<enforce> | <enforce> | ||
int result = 5; | int result = 5; | ||
Line 22: | Line 26: | ||
</enforce> | </enforce> | ||
This operator can be used ''before'' the value as well (it is then called ''pre-increment'' operator): | |||
<enforce> | |||
int result = 5; | |||
++result; // result is 6 | |||
</enforce> | |||
The difference is that the ''returned'' value is incremented too: <!-- let's not talk about how ++i ''may'' be faster than i++ here --> | |||
{| | |||
| <enforce> | |||
int result = 5; | |||
Print(result++); // outputs 5, result is 6 | |||
</enforce> | |||
| <enforce> | |||
int result = 5; | |||
Print(++result); // outputs 6, result is 6 | |||
</enforce> | |||
|} | |||
<div style="font-family: monospace"> | |||
==== -- ==== | ==== -- ==== | ||
The decrement operator removes 1 to the provided numerical variable. It only applies to int and float values. | </div> | ||
The decrement (or post-decrement) operator removes 1 to the provided numerical variable. It only applies to int and float values. | |||
<enforce> | <enforce> | ||
int result = 5; | int result = 5; | ||
Line 29: | Line 53: | ||
</enforce> | </enforce> | ||
Same as {{Link|#++}}, this operator can be used ''before'' the value (then called ''pre-decrement'' operator): | |||
<enforce> | |||
int result = 5; | |||
--result; // result is 4 | |||
</enforce> | |||
{| | |||
| <enforce> | |||
int result = 5; | |||
Print(result--); // outputs 5, result is 4 | |||
</enforce> | |||
| <enforce> | |||
int result = 5; | |||
Print(--result); // outputs 4, result is 4 | |||
</enforce> | |||
|} | |||
<div style="font-family: monospace"> | |||
==== +{{=}} ==== | ==== +{{=}} ==== | ||
</div> | |||
The "add to" operator adds the righthand value to the lefthand variable. | The "add to" operator adds the righthand value to the lefthand variable. | ||
<enforce> | <enforce> | ||
Line 36: | Line 79: | ||
</enforce> | </enforce> | ||
<div style="font-family: monospace"> | |||
==== -{{=}} ==== | ==== -{{=}} ==== | ||
</div> | |||
The "subtract from" operator subtract the righthand value to the lefthand variable. | The "subtract from" operator subtract the righthand value to the lefthand variable. | ||
<enforce> | <enforce> | ||
Line 43: | Line 88: | ||
</enforce> | </enforce> | ||
<div style="font-family: monospace"> | |||
==== *{{=}} ==== | ==== *{{=}} ==== | ||
</div> | |||
The "multiply with" operator multiplies the lefthand variable with the righthand value. | The "multiply with" operator multiplies the lefthand variable with the righthand value. | ||
<enforce> | <enforce> | ||
Line 50: | Line 97: | ||
</enforce> | </enforce> | ||
<div style="font-family: monospace"> | |||
==== /{{=}} ==== | ==== /{{=}} ==== | ||
</div> | |||
The "divide by" operator multiplies the lefthand variable with the righthand value. | The "divide by" operator multiplies the lefthand variable with the righthand value. | ||
<enforce> | <enforce> | ||
Line 59: | Line 108: | ||
=== Arithmetic === | === Arithmetic === | ||
<div style="font-family: monospace"> | |||
==== + ==== | ==== + ==== | ||
</div> | |||
he "adds" operator does an addition between two numeric values, float and/or integer. | he "adds" operator does an addition between two numeric values, float and/or integer. | ||
<enforce> | <enforce> | ||
Line 67: | Line 118: | ||
</enforce> | </enforce> | ||
<div style="font-family: monospace"> | |||
==== - ==== | ==== - ==== | ||
</div> | |||
The "subtract from" operator does a subtraction between two numerical values, float and/or integer. | The "subtract from" operator does a subtraction between two numerical values, float and/or integer. | ||
<enforce> | <enforce> | ||
Line 75: | Line 128: | ||
</enforce> | </enforce> | ||
<div style="font-family: monospace"> | |||
==== * ==== | ==== * ==== | ||
</div> | |||
The multiplication sign does a multiplication between two numerical values, float and/or integer. | The multiplication sign does a multiplication between two numerical values, float and/or integer. | ||
<enforce> | <enforce> | ||
Line 83: | Line 138: | ||
</enforce> | </enforce> | ||
<div style="font-family: monospace"> | |||
==== / ==== | ==== / ==== | ||
</div> | |||
The "divided by" operator divides the left argument by the right one.<br> | The "divided by" operator divides the left argument by the right one.<br> | ||
It can be applied to int, float or a mix of those. | It can be applied to int, float or a mix of those. | ||
Line 93: | Line 150: | ||
</enforce> | </enforce> | ||
<div style="font-family: monospace"> | |||
==== % ==== | ==== % ==== | ||
</div> | |||
Modulo is an operator that gives the remainder of a division.<br> | Modulo is an operator that gives the remainder of a division.<br> | ||
It only applies to integers. | It only applies to integers. | ||
{{Feature|informative|See the | {{Feature|informative|See the <enforce inline>Math.Repeat()</enforce> method for a float modulo approximation.}} | ||
<enforce> | <enforce> | ||
5 % 3; // result is 2: 5 is one time 3, remaining 2 | 5 % 3; // result is 2: 5 is one time 3, remaining 2 | ||
Line 105: | Line 164: | ||
=== Relational === | === Relational === | ||
<div style="font-family: monospace"> | |||
==== > ==== | ==== > ==== | ||
</div> | |||
The "greater than" operator returns '''true''' if the left argument is strictly greater than the right argument, false otherwise.<br> | The "greater than" operator returns '''true''' if the left argument is strictly greater than the right argument, false otherwise.<br> | ||
It can be applied to int, float or a mix of those. | It can be applied to int, float or a mix of those. | ||
Line 118: | Line 179: | ||
</enforce> | </enforce> | ||
<div style="font-family: monospace"> | |||
==== < ==== | ==== < ==== | ||
</div> | |||
The "lesser than" operator returns '''true''' if the left argument is strictly smaller than the right argument, false otherwise.<br> | The "lesser than" operator returns '''true''' if the left argument is strictly smaller than the right argument, false otherwise.<br> | ||
It can be applied to int, float or a mix of those. | It can be applied to int, float or a mix of those. | ||
Line 131: | Line 194: | ||
</enforce> | </enforce> | ||
<div style="font-family: monospace"> | |||
==== >{{=}} ==== | ==== >{{=}} ==== | ||
</div> | |||
The "greater than or equal" operator returns '''true''' if the left argument is greater than or equal to the right argument, false otherwise.<br> | The "greater than or equal" operator returns '''true''' if the left argument is greater than or equal to the right argument, false otherwise.<br> | ||
It can be applied to int, float or a mix of those. | It can be applied to int, float or a mix of those. | ||
Line 144: | Line 209: | ||
</enforce> | </enforce> | ||
<div style="font-family: monospace"> | |||
==== <{{=}} ==== | ==== <{{=}} ==== | ||
</div> | |||
The "lesser than or equal" operator returns '''true''' if the left argument is smaller than or equal to the right argument, false otherwise.<br> | The "lesser than or equal" operator returns '''true''' if the left argument is smaller than or equal to the right argument, false otherwise.<br> | ||
It can be applied to int, float or a mix of those. | It can be applied to int, float or a mix of those. | ||
Line 157: | Line 224: | ||
</enforce> | </enforce> | ||
<div style="font-family: monospace"> | |||
==== {{=}}{{=}} ==== | ==== {{=}}{{=}} ==== | ||
</div> | |||
The "equals" operator returns '''true''' if the left argument is strictly equal to the right argument, false otherwise. | The "equals" operator returns '''true''' if the left argument is strictly equal to the right argument, false otherwise. | ||
Line 189: | Line 258: | ||
</enforce> | </enforce> | ||
<div style="font-family: monospace"> | |||
==== !{{=}} ==== | ==== !{{=}} ==== | ||
</div> | |||
The "different" operator returns '''true''' if the left argument is different from the right argument, false otherwise. | The "different" operator returns '''true''' if the left argument is different from the right argument, false otherwise. | ||
Line 220: | Line 291: | ||
=== Logical === | === Logical === | ||
<div style="font-family: monospace"> | |||
==== && ==== | ==== && ==== | ||
</div> | |||
The "and" operator returns '''true''' if both left and right conditions are true. | The "and" operator returns '''true''' if both left and right conditions are true. | ||
<enforce> | <enforce> | ||
Line 236: | Line 309: | ||
</enforce> | </enforce> | ||
<div style="font-family: monospace"> | |||
==== {{!}}{{!}} ==== | ==== {{!}}{{!}} ==== | ||
</div> | |||
The "or" logical operator returns '''true''' if left or right condition is true (or both). | The "or" logical operator returns '''true''' if left or right condition is true (or both). | ||
<enforce> | <enforce> | ||
Line 252: | Line 327: | ||
</enforce> | </enforce> | ||
<div style="font-family: monospace"> | |||
==== ! ==== | ==== ! ==== | ||
</div> | |||
The "not" logical operator inverts a boolean value: {{hl|true}} becomes {{hl|false}} and {{hl|false}} becomes {{hl|true}}.<br> | The "not" logical operator inverts a boolean value: {{hl|true}} becomes {{hl|false}} and {{hl|false}} becomes {{hl|true}}.<br> | ||
It can also be used on: | It can also be used on: | ||
Line 301: | Line 378: | ||
=== Bitwise === | === Bitwise === | ||
<div style="font-family: monospace"> | |||
==== & ==== | ==== & ==== | ||
</div> | |||
The "bitwise AND" operator applies a AND operation between values bits - both bits must be 1 to return 1, otherwise 0 is returned. | The "bitwise AND" operator applies a AND operation between values bits - both bits must be 1 to return 1, otherwise 0 is returned. | ||
<enforce> | <enforce> | ||
Line 310: | Line 389: | ||
</enforce> | </enforce> | ||
<div style="font-family: monospace"> | |||
==== {{!}} ==== | ==== {{!}} ==== | ||
</div> | |||
The "bitwise OR" operator applies a OR operation between values bits - one of the bits must be 1 to return 1, otherwise 0 is returned. | The "bitwise OR" operator applies a OR operation between values bits - one of the bits must be 1 to return 1, otherwise 0 is returned. | ||
<enforce> | <enforce> | ||
Line 319: | Line 400: | ||
</enforce> | </enforce> | ||
<div style="font-family: monospace"> | |||
==== ~ ==== | ==== ~ ==== | ||
</div> | |||
The "bitwise NOT" operator reverts all bits of the provided value: 1 becomes 0 and vice-versa. | The "bitwise NOT" operator reverts all bits of the provided value: 1 becomes 0 and vice-versa. | ||
<enforce> | <enforce> | ||
Line 327: | Line 410: | ||
</enforce> | </enforce> | ||
<div style="font-family: monospace"> | |||
==== << ==== | ==== << ==== | ||
</div> | |||
The left shift operator moves all bits of the provided value to the left. | The left shift operator moves all bits of the provided value to the left. | ||
<enforce> | <enforce> | ||
Line 338: | Line 423: | ||
</enforce> | </enforce> | ||
<div style="font-family: monospace"> | |||
==== >> ==== | ==== >> ==== | ||
</div> | |||
The right shift operator moves bits of the provided value to the right. | The right shift operator moves bits of the provided value to the right. | ||
<enforce> | <enforce> | ||
Line 351: | Line 438: | ||
=== String === | === String === | ||
<div style="font-family: monospace"> | |||
==== + ==== | ==== + ==== | ||
</div> | |||
The "adds" operator used with strings concatenates them. | The "adds" operator used with strings concatenates them. | ||
When it is used with string and another type, it will stringify (calling its .ToString() method) the other value. | When it is used with string and another type, it will stringify (calling its .ToString() method) the other value. | ||
Line 378: | Line 467: | ||
=== Indexing === | === Indexing === | ||
<div style="font-family: monospace"> | |||
==== <nowiki>[]</nowiki> ==== | ==== <nowiki>[]</nowiki> ==== | ||
</div> | |||
The "get index" operator is used on arrays to get an element by its '''zero-based''' index (e.g 0 is first element, 1 is second, etc). | The "get index" operator is used on arrays to get an element by its '''zero-based''' index (e.g 0 is first element, 1 is second, etc). | ||
It can also be used on strings, as strings are arrays of characters. | It can also be used on strings, as strings are arrays of characters. | ||
Line 391: | Line 482: | ||
string thirdLetter = text[2]; // result is "C" | string thirdLetter = text[2]; // result is "C" | ||
</enforce> | </enforce> | ||
{{Feature|important| | |||
The {{hl|[i]}} operator is equivalent to a <enforce inline>.Get(i)</enforce> method call; in order to save unrequired method calls, either use {{Link|Arma Reforger:Scripting: Keywords#foreach|foreach}} or cache the call result whenever possible. | |||
<enforce> | |||
for (int i, count = myArray.Count(); i < count; i++) | |||
{ | |||
if (myArray[i].IsEmpty()) // .Get(i) equivalent | |||
Print("#" + i + " is empty"); | |||
else | |||
Print("trimmed '" + myArray[i] + "' is '" + myArray[i].Trim() . "'"); // .Get(i) equivalent, twice | |||
} | |||
</enforce> | |||
<enforce> | |||
for (int i, count = myArray.Count(); i < count; i++) | |||
{ | |||
string value = myArray[i]; // .Get(i) equivalent | |||
if (value.IsEmpty()) | |||
Print("#" + i + " is empty"); | |||
else | |||
Print("trimmed '" + value + "' is '" + value.Trim() . "'"); | |||
} | |||
</enforce> | |||
<enforce> | |||
foreach (int i, string value : myArray) | |||
{ | |||
if (value.IsEmpty()) | |||
Print("#" + i + " is empty"); | |||
else | |||
Print("trimmed '" + value + "' is '" + value.Trim() . "'"); | |||
} | |||
</enforce> | |||
}} | |||
== Precedence == | == Precedence == | ||
Operators precedence (one having execution priority over another) in Enforce Script is identical to the C language: see the {{Link|https://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Operator_precedence|Wikipedia article section}}. | Operators precedence (one having execution priority over another) in Enforce Script is identical to the C language: | ||
see the {{Link|https://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Operator_precedence|Wikipedia article section}}. | |||
<!-- | |||
TODO: remove things that do not exist in Enforce Script | |||
{| class="wikitable" | |||
! Precedence | |||
! Operator | |||
! Description | |||
! Associativity | |||
|- | |||
! 1 | |||
<small>highest</small> | |||
| <code>::</code> | |||
| [[:en:Scope_resolution_operator#C.2B.2B|Scope resolution]] (C++ only) | |||
| None | |||
|- | |||
! rowspan="11" | 2 | |||
| <code>++</code> | |||
| Postfix increment | |||
| rowspan="11" | Left-to-right | |||
|- | |||
| <code>--</code> | |||
| Postfix decrement | |||
|- | |||
| <code>()</code> | |||
| Function call | |||
|- | |||
| <code>[]</code> | |||
| Array subscripting | |||
|- | |||
| <code>.</code> | |||
| Element selection by reference | |||
|- | |||
| <code>-></code> | |||
| Element selection through pointer | |||
|- | |||
| <code>typeid()</code> | |||
| [[:en:Run-time_type_information|Run-time type information]] (C++ only) (see [[:en:Typeid|typeid]]) | |||
|- | |||
| <code>const_cast</code> | |||
| Type cast (C++ only) (see [[:en:Const_cast|const_cast]]) | |||
|- | |||
| <code>dynamic_cast</code> | |||
| Type cast (C++ only) (see [[:en:Dynamic_cast|dynamic cast]]) | |||
|- | |||
| <code>reinterpret_cast</code> | |||
| Type cast (C++ only) (see [[:en:Reinterpret_cast|reinterpret_cast]]) | |||
|- | |||
| <code>static_cast</code> | |||
| Type cast (C++ only) (see [[:en:Static_cast|static_cast]]) | |||
|- | |||
! rowspan="13" | 3 | |||
| <code>++</code> | |||
| Prefix increment | |||
| rowspan="13" |Right-to-left | |||
|- | |||
| <code>--</code> | |||
| Prefix decrement | |||
|- | |||
| <code>+</code> | |||
| Unary plus | |||
|- | |||
| <code>-</code> | |||
| Unary minus | |||
|- | |||
| <code>!</code> | |||
| Logical NOT | |||
|- | |||
| <code>~</code> | |||
| Bitwise NOT (Ones' Complement) | |||
|- | |||
| <code>(''type'')</code> | |||
| Type cast | |||
|- | |||
| <code>*</code> | |||
| Indirection (dereference) | |||
|- | |||
| <code>&</code> | |||
| Address-of | |||
|- | |||
| <code>sizeof</code> | |||
| [[:en:Sizeof|Sizeof]] | |||
|- | |||
| <code>_Alignof</code> | |||
| Alignment requirement (since C11) | |||
|- | |||
| <code>new</code>, <code>new[]</code> | |||
| Dynamic memory allocation (C++ only) | |||
|- | |||
| <code>delete</code>, <code>delete[]</code> | |||
| Dynamic memory deallocation (C++ only) | |||
|- | |||
! rowspan="2" | 4 | |||
| <code>.*</code> | |||
| Pointer to member (C++ only) | |||
| rowspan="2" | Left-to-right | |||
|- | |||
| <code>->*</code> | |||
| Pointer to member (C++ only) | |||
|- | |||
! rowspan="3" | 5 | |||
| <code>*</code> | |||
| Multiplication | |||
| rowspan="3" | Left-to-right | |||
|- | |||
| <code>/</code> | |||
| Division | |||
|- | |||
| <code>%</code> | |||
| [[:en:Modulo_operation|Modulo]] (remainder) | |||
|- | |||
! rowspan="2" | 6 | |||
| <code>+</code> | |||
| Addition | |||
| rowspan="2" | Left-to-right | |||
|- | |||
| <code>-</code> | |||
| Subtraction | |||
|- | |||
! rowspan="2" | 7 | |||
| <code><<</code> | |||
| [[:en:Bitwise_operation|Bitwise]] left shift | |||
| rowspan="2" | Left-to-right | |||
|- | |||
| <code>>></code> | |||
| [[:en:Bitwise_operation|Bitwise]] right shift | |||
|- | |||
! rowspan="1" | 8 | |||
| <code><=></code> | |||
| [[:en:Three-way_comparison|Three-way comparison]] (Introduced in [[:en:C++20|C++20]] - C++ only) | |||
| rowspan="1" | Left-to-right | |||
|- | |||
! rowspan="4" | 9 | |||
| <code><</code> | |||
| Less than | |||
| rowspan="4" | Left-to-right | |||
|- | |||
| <code><=</code> | |||
| Less than or equal to | |||
|- | |||
| <code>></code> | |||
| Greater than | |||
|- | |||
| <code>>=</code> | |||
| Greater than or equal to | |||
|- | |||
! rowspan="2" | 10 | |||
| <code>==</code> | |||
| Equal to | |||
| rowspan="2" | Left-to-right | |||
|- | |||
| <code>!=</code> | |||
| Not equal to | |||
|- | |||
! 11 | |||
| <code>&</code> | |||
| Bitwise AND | |||
| Left-to-right | |||
|- | |||
! 12 | |||
| <code>^</code> | |||
| Bitwise XOR (exclusive or) | |||
| Left-to-right | |||
|- | |||
! 13 | |||
| <code><nowiki>| </nowiki></code> | |||
| Bitwise OR (inclusive or) | |||
| Left-to-right | |||
|- | |||
! 14 | |||
| <code>&&</code> | |||
| Logical AND | |||
| Left-to-right | |||
|- | |||
! 15 | |||
| <code><nowiki>|| </nowiki></code> | |||
| Logical OR | |||
| Left-to-right | |||
|- | |||
! rowspan="2" | 16 | |||
| <code>co_await</code> | |||
| rowspan="2" |Coroutine processing (C++ only) | |||
| rowspan="2" |Right-to-left | |||
|- | |||
| <code>co_yield</code> | |||
|- | |||
! rowspan="13" | 17 | |||
| <code>?:</code> | |||
| [[:en:Ternary_conditional_operator|Ternary conditional operator]] | |||
| rowspan="13" |Right-to-left | |||
|- | |||
| <code>=</code> | |||
| Direct assignment | |||
|- | |||
| <code>+=</code> | |||
| Assignment by sum | |||
|- | |||
| <code>-=</code> | |||
| Assignment by difference | |||
|- | |||
| <code>*=</code> | |||
| Assignment by product | |||
|- | |||
| <code>/=</code> | |||
| Assignment by quotient | |||
|- | |||
| <code>%=</code> | |||
| Assignment by remainder | |||
|- | |||
| <code><<=</code> | |||
| Assignment by bitwise left shift | |||
|- | |||
| <code>>>=</code> | |||
| Assignment by bitwise right shift | |||
|- | |||
| <code>&=</code> | |||
| Assignment by bitwise AND | |||
|- | |||
| <code>^=</code> | |||
| Assignment by bitwise XOR | |||
|- | |||
| <code><nowiki>|=</nowiki></code> | |||
| Assignment by bitwise OR | |||
|- | |||
| <code>throw</code> | |||
| Throw operator (exceptions throwing, C++ only) | |||
|- | |||
! 18 | |||
<small>lowest</small> | |||
| <code>,</code> | |||
| [[:en:Comma_operator|Comma]] | |||
| Left-to-right | |||
|} | |||
--> | |||
{{GameCategory|armaR|Modding|Guidelines|Scripting}} | {{GameCategory|armaR|Modding|Guidelines|Scripting}} |
Revision as of 20:47, 16 June 2023
Operators are elements used to generate operations between two values.
Types
Assignment
=
The "assign operator sets the righthand value to the lefthand variable.
++
The increment (or post-increment) operator adds 1 to the provided numerical variable. It only applies to int and float values.
This operator can be used before the value as well (it is then called pre-increment operator):
The difference is that the returned value is incremented too:
--
The decrement (or post-decrement) operator removes 1 to the provided numerical variable. It only applies to int and float values.
Same as ++, this operator can be used before the value (then called pre-decrement operator):
+=
The "add to" operator adds the righthand value to the lefthand variable.
-=
The "subtract from" operator subtract the righthand value to the lefthand variable.
*=
The "multiply with" operator multiplies the lefthand variable with the righthand value.
/=
The "divide by" operator multiplies the lefthand variable with the righthand value.
Arithmetic
+
he "adds" operator does an addition between two numeric values, float and/or integer.
-
The "subtract from" operator does a subtraction between two numerical values, float and/or integer.
*
The multiplication sign does a multiplication between two numerical values, float and/or integer.
/
The "divided by" operator divides the left argument by the right one.
It can be applied to int, float or a mix of those.
If both values are int, the return value will be a floored integer as well.
%
Modulo is an operator that gives the remainder of a division.
It only applies to integers.
Relational
>
The "greater than" operator returns true if the left argument is strictly greater than the right argument, false otherwise.
It can be applied to int, float or a mix of those.
<
The "lesser than" operator returns true if the left argument is strictly smaller than the right argument, false otherwise.
It can be applied to int, float or a mix of those.
>=
The "greater than or equal" operator returns true if the left argument is greater than or equal to the right argument, false otherwise.
It can be applied to int, float or a mix of those.
<=
The "lesser than or equal" operator returns true if the left argument is smaller than or equal to the right argument, false otherwise.
It can be applied to int, float or a mix of those.
==
The "equals" operator returns true if the left argument is strictly equal to the right argument, false otherwise.
Applies to:
- boolean
- int
- float
- int / float, float / int
- string (case-sensitive)
- vector (value)
- array (reference)
- object (reference)
!=
The "different" operator returns true if the left argument is different from the right argument, false otherwise.
Applies to:
- boolean
- int
- float
- int / float, float / int
- string (case-sensitive)
- vector (value)
- array (reference)
- object (reference)
Logical
&&
The "and" operator returns true if both left and right conditions are true.
||
The "or" logical operator returns true if left or right condition is true (or both).
!
The "not" logical operator inverts a boolean value: true becomes false and false becomes true.
It can also be used on:
- int or float (0 comparison)
- string (empty string comparison - usage of the string.IsEmpty() method is preferred)
- object (null comparison)
Bitwise
&
The "bitwise AND" operator applies a AND operation between values bits - both bits must be 1 to return 1, otherwise 0 is returned.
|
The "bitwise OR" operator applies a OR operation between values bits - one of the bits must be 1 to return 1, otherwise 0 is returned.
~
The "bitwise NOT" operator reverts all bits of the provided value: 1 becomes 0 and vice-versa.
<<
The left shift operator moves all bits of the provided value to the left.
>>
The right shift operator moves bits of the provided value to the right.
String
+
The "adds" operator used with strings concatenates them. When it is used with string and another type, it will stringify (calling its .ToString() method) the other value. The left argument must be of string type for it to happen.
Indexing
[]
The "get index" operator is used on arrays to get an element by its zero-based index (e.g 0 is first element, 1 is second, etc). It can also be used on strings, as strings are arrays of characters.
Precedence
Operators precedence (one having execution priority over another) in Enforce Script is identical to the C language: see the Wikipedia article section.