Operators: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (→‎Rules of Precedence: made brackets clearer)
(Added section for config operators | Added += config operator | Added examples for += config operator)
 
(18 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{SideTOC}}
{{TOC|side}}
'''Operators''' are the base commands each programming language is built on. They provide ability to perform basic mathematical and logical operations.
'''Operators''' are the base commands each programming language is built on. They provide ability to perform basic mathematical and logical operations.


Line 16: Line 16:


; Expression
; Expression
: An expression is basically any code that returns a value. Read [[Expression]] for more information.
: An expression is basically any code that returns a value. Read [[Expression|expression]] for more information.


; Unary Operator
; Unary Operator
Line 22: Line 22:
:
:
: Unary operation:
: Unary operation:
: <code>''operator'' [[expression]]</code>
: <code style="display: block">''operator'' [[Expression|expression]]</code>


; Binary Operator
; Binary Operator
Line 28: Line 28:
:
:
: Binary operation:
: Binary operation:
: <code>[[expression]] ''operator'' [[expression]]</code>
: <code style="display: block">[[Expression|expression]] ''operator'' [[Expression|expression]]</code>




Line 36: Line 36:


Assignment operators are used to assign values to a [[Variables|variable]]. OFP's scripting language provides only one assignment operator.
Assignment operators are used to assign values to a [[Variables|variable]]. OFP's scripting language provides only one assignment operator.


'''Assignment:'''
'''Assignment:'''
 
  [[Identifier|identifier]] = [[Expression|expression]]
  [[identifier]] = [[expression]]
 


'''Example 1:'''
'''Example 1:'''
a = b
<sqf>a = b</sqf>
 
You might think that this operator compares <tt>a</tt> and <tt>b</tt>, but that is not the case. <tt>=</tt> simply sets the left value to be the right one. There don't exist any other assignment operators like <tt>+=</tt>, <tt>-=</tt> etc., that can be found in other programming languages.


You might think that this operator compares {{hl|a}} and {{hl|b}}, but that is not the case. {{hl|{{=}}}} simply sets the left value to be the right one. Other assignment operators like {{hl|c= +=}}, {{hl|c= -=}} that can be found in other programming languages do not exist in [[SQF Syntax|SQF]]/[[SQS Syntax|SQS]].


'''Example 2:'''
'''Example 2:'''
a = b*c
<sqf>a = b * c</sqf>


=== Arithmetic Operators ===
=== Arithmetic Operators ===


Remember arithmetic operations from school? These work just the same way.
Remember arithmetic operations from school? These work just the same way.
All operands of arithmetic operations must be [[Number]]s. Arithmetic operations always return a [[Number]].


All operands of arithmetic operations must be [[Number|Numbers]]. Arithmetic operations always return a [[Number]].
{| class="wikitable"
 
{| class="operators"
|+ Unary arithmetic operators (in order of precedence)
|+ Unary arithmetic operators (in order of precedence)
! Operator !! Name !! Example
! Operator !! Name !! Example
|-
|-
| - || Negation || <tt>-a, +-a, -+a</tt>
| - || Negation || <sqf>-a</sqf>
|-
|-
| + || Posation || <tt>+a</tt>
| + || Duplication || <sqf>+a</sqf>
|-
|-
| ( || Bracket  || <tt>(expression)</tt>
| ( || Bracket  || <sqf>(expression)</sqf>
|}
|}


{| class="operators"
{| class="wikitable"
|+ Binary arithmetic operators
|+ Binary arithmetic operators
! Operator !! Name !! Example
! Operator !! Name !! Example
|-
|-
| + || Addition || <tt>a + b</tt>
| + || Addition || <sqf>a + b</sqf>
|-
|-
| - || Subtraction || <tt>a - b</tt>
| - || Subtraction || <sqf>a - b</sqf>
|-
|-
| * || Multiplication || <tt>a * b</tt>
| * || Multiplication || <sqf>a * b</sqf>
|-
|-
| / || Division || <tt>a / b</tt>
| / || Division || <sqf>a / b</sqf>
|-
|-
| % || Modulo || <tt>a % b</tt>
| % || Modulo || <sqf>a % b</sqf>
|-
|-
| mod || Modulo || <tt>a mod b</tt>
| mod || Modulo || <sqf>a mod b</sqf>
|-
|-
| ^ || Raise to the power of || <tt>a ^ b</tt>
| ^ || Raise to the power of || <sqf>a ^ b</sqf>
|}
|}


'''Modulo''' returns the remainder of the division <tt>a / b</tt>.
{{Feature|informative|See also [[:Category:Command Group: Math|Math Commands]].}}
 
 
'''See also:''' [[:Category:Command Group: Math|Math Commands]]
 


=== Logical Operators ===
=== Logical Operators ===


Logical operators evaluate [[Boolean]] values. All operands of logical operations are [[Boolean]]s.
Logical operators evaluate [[Boolean]] values. All operands of logical operations are [[Boolean]]s.
A logical operation always returns a [[Boolean]].
A logical operation always returns a [[Boolean]].


{| class="operators"
{| class="wikitable"
|+ Unary logical operators
|+ Unary logical operators
! Operator !! Name !! Example
! Operator !! Name !! Example
|-
|-
| ! || Not || <tt>!a</tt>
| ! || Not || <sqf>!a</sqf>
|-
|-
| not || Not || <tt>not a</tt>
| not || Not || <sqf>not a</sqf>
|}
|}


The <tt>Not</tt>-operator always returns the inverse [[Boolean]] value. If a [[Boolean]] <tt>a</tt> is <tt>true</tt>, <tt>!a</tt> returns <tt>false</tt> and vice versa.
The {{hl|Not}}-operator always returns the inverse [[Boolean]] value. If a [[Boolean]] {{hl|a}} is {{hl|true}}, {{hl|!a}} returns {{hl|false}} and vice versa.


{| class="operators"
{| class="wikitable"
|+ Binary logical operators
|+ Binary logical operators
! Operator !! Name !! Example
! Operator !! Name !! Example
|-
|-
| && || And || <tt>a && b</tt>
| && || And || <sqf>a && b</sqf>
|-
|-
| and || And || <tt>a and b</tt>
| and || And || <sqf>a and b</sqf>
|-
|-
| <nowiki>||</nowiki> || Or || <tt>a <nowiki>||</nowiki> b</tt>
| <nowiki>||</nowiki> || Or || <sqf>a || b</sqf>
|-
|-
| or || Or || <tt>a or b</tt>
| or || Or || <sqf>a or b</sqf>
|}
|}


* <tt>And</tt> only returns <tt>true</tt> if ''both'' operands are <tt>true</tt>
* {{hl|And}} only returns {{hl|true}} if ''both'' operands are {{hl|true}}
* <tt>Or</tt> returns <tt>true</tt> if ''one or both'' operands are <tt>true</tt>
* {{hl|Or}} returns {{hl|true}} if ''one or both'' operands are {{hl|true}}




There is no Xor, Nor and Nand operator. Those can be simulated using the basic operators though:
There is no Xor, Nor and Nand operator. Those can be simulated using the basic operators though:


{| class="operators"
{| class="wikitable"
|+ Combined logical operators
|+ Combined logical operators
! Name !! Combination
! Name !! Combination
|-
|-
| Xor || <tt>((a <nowiki>||</nowiki> b) && !(a && b))</tt>
| Xor || <sqf>((a || b) && !(a && b))</sqf>
|-
|-
| Nor || <tt>!(a <nowiki>||</nowiki> b)</tt>
| Nor || <sqf>!(a || b)</sqf>
|-
|-
| Nand || <tt>!(a && b)</tt>
| Nand || <sqf>!(a && b)</sqf>
|}
|}


* <tt>Xor</tt> returns <tt>true</tt> if ''exactly one'' of both values is <tt>true</tt>
* {{hl|Xor}} returns {{hl|true}} if ''exactly one'' of both values is {{hl|true}}
* <tt>Nor</tt> returns <tt>true</tt> if ''none'' of both values is <tt>true</tt>
* {{hl|Nor}} returns {{hl|true}} if ''none'' of both values is {{hl|true}}
* <tt>Nand</tt> returns <tt>true</tt> if ''not both'' values are <tt>true</tt> at the same time
* {{hl|Nand}} returns {{hl|true}} if ''not both'' values are {{hl|true}} at the same time


=== Comparison Operators ===
=== Comparison Operators ===


Comparison operators compare two values. Operands of comparisons may be of type [[Number]], [[Side]], [[String]], [[Object]], [[Group]], [[Structured Text]], [[Config]], [[Display]] or [[Control]] for <tt>==</tt> and <tt>!=</tt> , and [[Number]] for <tt>< > >= <= </tt>
Comparison operators compare two values. Operands of comparisons may be of type [[Number]], [[Side]], [[String]], [[Object]], [[Group]], [[Structured Text]], [[Config]], [[Display]] or [[Control]] for {{hl|c= ==}} and {{hl|c= !=}}, and [[Number]] for {{hl|c= < > >= <=}}.
Comparisons always return a [[Boolean]]: {{hl|true}} if the comparison matches, {{hl|false}} if not.


Comparisons always return a [[Boolean]]: <tt>true</tt> if the comparison matches, <tt>false</tt> if not.
{| class="wikitable"
 
{| class="operators"
|+ Comparison operators
|+ Comparison operators
! Operator !! Name !! Example
! Operator !! Name !! Example
|-
|-
| == || Equal || <tt>a == b</tt>
| == || Equal || <sqf>a == b</sqf>
|-
|-
| != || Not equal || <tt>a != b</tt>
| != || Not equal || <sqf>a != b</sqf>
|-
|-
| < || Less than || <tt>a < b</tt>
| < || Less than || <sqf>a < b</sqf>
|-
|-
| > || Greater than || <tt>a > b</tt>
| > || Greater than || <sqf>a > b</sqf>
|-
|-
| <= || Less or equal || <tt>a <= b</tt>
| <= || Less or equal || <sqf>a <= b</sqf>
|-
|-
| >= || Greater or equal || <tt>a >= b</tt>
| >= || Greater or equal || <sqf>a >= b</sqf>
|}
|}


{{Informative |
{{Feature|informative|2=
{{{!}} class{{=}}"wikitable" style{{=}}"float: right"
{{{!}} class="wikitable" style="float: right"
! invalid before {{arma3}} v2.00
! invalid before {{arma3}} v2.00
! valid in all versions
! valid in all versions
{{!}}-
{{!}}-
{{!}} <code>a {{=}}{{=}} [[true]]</code>
{{!}} <sqf>a == true</sqf>
{{!}} <code>a</code>
{{!}} <sqf>a</sqf>
{{!}}-
{{!}}-
{{!}} <code>a {{=}}{{=}} [[false]]</code>
{{!}} <sqf>a == false</sqf>
{{!}} <code>!a</code>
{{!}} <sqf>!a</sqf>
{{!}}}
{{!}}}
You could not compare [[Boolean]] values with [[a {{=}}{{=}} b|{{=}}{{=}}]] before '''{{arma3}} v1.99.146526''' (in {{arma3}} before that, use [[isEqualTo]]).<br><!--
You could not compare [[Boolean]] values with [[a {{=}}{{=}} b|{{=}}{{=}}]] before '''{{arma3}} v2.00''' (in {{arma3}} before that, use [[isEqualTo]]).<br><!--
-->Comparing a [[Boolean]] value with <tt>[[true]]</tt> is the same as the value itself.<br><!--
-->Comparing a [[Boolean]] value with {{hl|[[true]]}} is the same as the value itself.<br><!--
-->Comparing a [[Boolean]] value with <tt>[[false]]</tt> is the same as the ''inverse'' value.
-->Comparing a [[Boolean]] value with {{hl|[[false]]}} is the same as the ''inverse'' value.
}}
}}


Line 187: Line 176:


The scripting language offers own operators to deal with arrays. All operands, of course, have to be of type [[Array]].
The scripting language offers own operators to deal with arrays. All operands, of course, have to be of type [[Array]].
The return value of an array operation is an [[Array]].
The return value of an array operation is an [[Array]].


{| class="operators"
{| class="wikitable"
|+ Unary array operators
|+ Unary array operators
! Operator !! Name !! Example
! Operator !! Name !! Example
|-
|-
| + || Copy || <tt>+myArray</tt>
| + || Copy || <sqf>+myArray</sqf>
|}
|}


Normally arrays are assigned ''by reference''. That means, if you assign array <tt>a</tt> to array <tt>b</tt> and change <tt>a</tt> afterwards, also <tt>b</tt> is changed. Use the copy operator to avoid this otherwise useful feature.
Normally arrays are assigned ''by reference''. That means, if you assign array {{hl|a}} to array {{hl|b}} and change {{hl|a}} afterwards, also {{hl|b}} is changed. Use the copy operator to avoid this otherwise useful feature.


'''Example 1:'''
'''Example 1:'''
<sqf>
_arrayA = [1,2];
_arrayB = _arrayA;
_arrayA set [0,5];


_arrayA = [1,2];
// _arrayA => [5,2]
_arrayB = _arrayA;
// _arrayB => [5,2]
_arrayA set [0,5];
</sqf>
_arrayA => [5,2]
_arrayB => [5,2]


'''Example 2:'''
'''Example 2:'''
<sqf>
_arrayA = [1,2];
_arrayB = +_arrayA;
_arrayA set [0,5];


_arrayA = [1,2];
// _arrayA => [5,2]
_arrayB = +_arrayA;
// _arrayB => [1,2]
_arrayA set [0,5];
</sqf>
_arrayA => [5,2]
_arrayB => [1,2]


{| class="operators"
{| class="wikitable"
|+ Binary array operators
|+ Binary array operators
! Operator !! Name !! Example
! Operator !! Name !! Example
|-
|-
| + || Concatenation || <tt>myArray1 + myArray2</tt>
| + || Concatenation || <sqf>myArray1 + myArray2</sqf>
|-
|-
| - || Removal || <tt>myArray1 - myArray2</tt>
| - || Removal || <sqf>myArray1 - myArray2</sqf>
|}
|}


* <tt>+</tt> adds the second operand on the end of the first operand
* {{hl|+}} adds the second operand on the end of the first operand
* <tt>-</tt> removes all elements of the second operand from the first operand
* {{hl|-}} removes all elements of the second operand from the first operand


'''Example 1:'''
'''Example 1:'''
<sqf>
_arrayA = [1,2];
_arrayB = [3,2,4];
_arrayC = _arrayA + _arrayB;


_arrayA = [1,2];
// _arrayC => [1,2,3,2,4]
_arrayB = [3,2,4];
</sqf>
_arrayC = _arrayA + _arrayB;
_arrayC => [1,2,3,2,4]


'''Example 2:'''
'''Example 2:'''
<sqf>
_arrayA = [1,2,3,2,4];
_arrayB = [2,3];


_arrayA = [1,2,3,2,4];
_arrayC = _arrayA - _arrayB;
_arrayB = [2,3];
 
// _arrayC => [1,4]
_arrayC = _arrayA - _arrayB;
</sqf>
_arrayC => [1,4]


=== String Operators ===
=== String Operators ===


The scripting language offers one single string operator to concatenate strings. Both operands must be [[String|Strings]].
The scripting language offers one single string operator to concatenate strings. Both operands must be [[String]]s.
 
The return value of a string operation is a [[String]].
The return value of a string operation is a [[String]].


{| class="operators"
{| class="wikitable"
|+ Binary string operators
|+ Binary string operators
! Operator !! Name !! Example
! Operator !! Name !! Example
|-
|-
| + || Concatenation || <tt>myString1 + myString2</tt>
| + || Concatenation || <sqf>myString1 + myString2</sqf>
|}
|}


* <tt>+</tt> adds the second operand on the end of the first operand
* {{hl|+}} adds the second operand on the end of the first operand


'''Example:'''
'''Example:'''
<sqf>
_stringA = "Hello ";
_stringB = "World!";


_stringA = "Hello ";
_stringC = _stringA + _stringB;
_stringB = "World!";
_stringC = _stringA + _stringB;
_stringC => "Hello World!"


// _stringC => "Hello World!"
</sqf>


== Rules of Precedence ==
=== Config Operators ===


{{Informative |
{| class="wikitable"
* Highest precedence means highest priority
|+ Config operators
* Associativity is (then) done from left to right, for example {{Inline code|3 + 5 + 8}} will be processed as {{Inline code|((3 + 5) + 8)}}
! Operator !! Name !! Example
}}
 
{| class="operators"
|-
|-
! Prece-<br>dence
| += || Append Array || <syntaxhighlight lang="cpp">myProperty[] += {element_1, element_2};</syntaxhighlight>
! Type of Operator
|}
! Examples
|-
| style="text-align: center" | 11
|
Nular operators (commands with no arguments):
* <tt>commandName</tt>
|
* [[Variables]]
* Values
* Braced expressions
|-
| style="text-align: center" | 10
|
Unary operators (commands with 1 argument):
* <tt>commandName</tt> a
|
* [[+ |+a]]
* [[- | -a]]


* [[+ | +array]]
'''Example:'''
<syntaxhighlight lang="cpp">
class B_Soldier_F;
class MySoldier: B_Soldier_F
{
RespawnItems[] += {"FirstAidKit"}; //Adds additional FAK
};


* [[!_a | !b]]
/*
* [[not | not b]]
Original RespawnItems[] array in config viewer:
|-
RespawnItems[] = {"FirstAidKit"};
| style="text-align: center" | 9
| Hash-select operator
|
* [[a_hash_b| array # index]]
|-
| style="text-align: center" | 8
| Power operator
|
* [[a ^ b]]
|-
| style="text-align: center" | 7
|
* [[Number]] multiplication, division and remainder
* [[atan2]]
* [[Config]] access ([[config / name|/]])
|
* [[a * b]]
* [[a / b]]
* [[a % b]]
* [[mod | a mod b]]
 
* [[config / name]]


* [[atan2| a atan2 b]]
Modified RespawnItems[] array in config viewer:
|-
RespawnItems[] = {"FirstAidKit","FirstAidKit"};
| style="text-align: center" | 6
*/
|
</syntaxhighlight>
* [[Number]] addition and subtraction
* [[Array]] addition and subtraction
* [[String]] addition
* [[min]] and [[max]] commands
|
* [[+ | a + b]]
* [[- | a - b]]


* [[+ | arr1 + arr2]]
== Order of Precedence ==
* [[- | arr1 - arr2]]


* [[+ | str1 + str2]]
{{:Order of Precedence}}


* [[min | a min b]]
* [[max | a max b]]
|-
| style="text-align: center" | 5
|
* [[else]] ([[if]]-[[then]]-[[else]] structure)
| {{n/a}}
|-
| style="text-align: center" | 4
|
Binary operators (commands with 2 arguments):
* a <tt>commandName</tt> b
|
* [[setDir]]
* [[a_:_b |switch colon(:)]]
|-
| style="text-align: center" | 3
|
* [[a == b|==]] and [[a != b|!=]] comparisons
* [[Number]] comparisons
* [[Config]] access ([[config greater greater name|&gt;&gt;]])
|
* [[a == b]]
* [[a != b]]
* [[a_greater_b| a &gt; b]]
* [[a_less_b| a &lt; b]]
* [[a_less=_b| a &gt;= b]]
* [[a_less=_b| a &lt;= b]]
* [[config_greater_greater_name | config >> name]]
|-
| style="text-align: center" | 2
| Logical [[and]] operator
|
* [[a && b|&&]]
* [[and]]
|-
| style="text-align: center" | 1
| Logical [[or]] operator
|
* [[a or b|<nowiki/>||]]
* [[or]]
|}
=== Examples ===
{| class="wikitable"
! Input
! Process
! Comment
|-
|
1 + 2 * 3
|
1 + (2 * 3)
| result equals 7, and not 9 (see also {{Wikipedia|Order of operations|PEMDAS}})
|-
|
[[sleep]] 10 + [[random]] 20
|
([[sleep]] 10) + [[random]] 20
| {{Inline code|[[sleep]] 10}} will return [[Nothing]], then {{Inline code|+ [[random]] 20}} will be calculated but not used.<br>
{{Inline code|[[sleep]] (10 + [[random]] 20)}} should be used instead
|}


== See Also ==
== See Also ==


* [[SQF syntax]]
* [[SQF Syntax]]
* [[SQS Syntax]]




[[Category: Syntax]]
[[Category: Syntax]]
[[Category: Scripting Topics]]

Latest revision as of 04:49, 9 April 2024

Operators are the base commands each programming language is built on. They provide ability to perform basic mathematical and logical operations.


Requirements

To understand this article, you should read the following articles:


Terms

Operand
An operand is any value given to an operator.
Expression
An expression is basically any code that returns a value. Read expression for more information.
Unary Operator
An unary operator is an operator that requires only one operand.
Unary operation:
operator expression
Binary Operator
A binary operator is an operator that requires two operands.
Binary operation:
expression operator expression


Operators

Assignment Operators

Assignment operators are used to assign values to a variable. OFP's scripting language provides only one assignment operator.

Assignment:

identifier = expression

Example 1:

a = b

You might think that this operator compares a and b, but that is not the case. = simply sets the left value to be the right one. Other assignment operators like +=, -= that can be found in other programming languages do not exist in SQF/SQS.

Example 2:

a = b * c

Arithmetic Operators

Remember arithmetic operations from school? These work just the same way. All operands of arithmetic operations must be Numbers. Arithmetic operations always return a Number.

Unary arithmetic operators (in order of precedence)
Operator Name Example
- Negation
-a
+ Duplication
+a
( Bracket
(expression)
Binary arithmetic operators
Operator Name Example
+ Addition
a + b
- Subtraction
a - b
* Multiplication
a * b
/ Division
a / b
% Modulo
a % b
mod Modulo
a mod b
^ Raise to the power of
a ^ b
See also Math Commands.

Logical Operators

Logical operators evaluate Boolean values. All operands of logical operations are Booleans. A logical operation always returns a Boolean.

Unary logical operators
Operator Name Example
! Not
!a
not Not
not a

The Not-operator always returns the inverse Boolean value. If a Boolean a is true, !a returns false and vice versa.

Binary logical operators
Operator Name Example
&& And
a && b
and And
a and b
|| Or
a || b
or Or
a or b
  • And only returns true if both operands are true
  • Or returns true if one or both operands are true


There is no Xor, Nor and Nand operator. Those can be simulated using the basic operators though:

Combined logical operators
Name Combination
Xor
((a || b) && !(a && b))
Nor
!(a || b)
Nand
!(a && b)
  • Xor returns true if exactly one of both values is true
  • Nor returns true if none of both values is true
  • Nand returns true if not both values are true at the same time

Comparison Operators

Comparison operators compare two values. Operands of comparisons may be of type Number, Side, String, Object, Group, Structured Text, Config, Display or Control for == and !=, and Number for < > >= <=. Comparisons always return a Boolean: true if the comparison matches, false if not.

Comparison operators
Operator Name Example
== Equal
a == b
!= Not equal
a != b
< Less than
a < b
> Greater than
a > b
<= Less or equal
a <= b
>= Greater or equal
a >= b
invalid before Arma 3 v2.00 valid in all versions
a
!a
You could not compare Boolean values with == before Arma 3 v2.00 (in Arma 3 before that, use isEqualTo).
Comparing a Boolean value with true is the same as the value itself.
Comparing a Boolean value with false is the same as the inverse value.

Array Operators

The scripting language offers own operators to deal with arrays. All operands, of course, have to be of type Array. The return value of an array operation is an Array.

Unary array operators
Operator Name Example
+ Copy
+myArray

Normally arrays are assigned by reference. That means, if you assign array a to array b and change a afterwards, also b is changed. Use the copy operator to avoid this otherwise useful feature.

Example 1:

_arrayA = [1,2]; _arrayB = _arrayA; _arrayA set [0,5]; // _arrayA => [5,2] // _arrayB => [5,2]

Example 2:

_arrayA = [1,2]; _arrayB = +_arrayA; _arrayA set [0,5]; // _arrayA => [5,2] // _arrayB => [1,2]

Binary array operators
Operator Name Example
+ Concatenation
myArray1 + myArray2
- Removal
myArray1 - myArray2
  • + adds the second operand on the end of the first operand
  • - removes all elements of the second operand from the first operand

Example 1:

_arrayA = [1,2]; _arrayB = [3,2,4]; _arrayC = _arrayA + _arrayB; // _arrayC => [1,2,3,2,4]

Example 2:

_arrayA = [1,2,3,2,4]; _arrayB = [2,3]; _arrayC = _arrayA - _arrayB; // _arrayC => [1,4]

String Operators

The scripting language offers one single string operator to concatenate strings. Both operands must be Strings. The return value of a string operation is a String.

Binary string operators
Operator Name Example
+ Concatenation
myString1 + myString2
  • + adds the second operand on the end of the first operand

Example:

_stringA = "Hello "; _stringB = "World!"; _stringC = _stringA + _stringB; // _stringC => "Hello World!"

Config Operators

Config operators
Operator Name Example
+= Append Array
myProperty[] += {element_1, element_2};

Example:

class B_Soldier_F;
class MySoldier: B_Soldier_F
{
	RespawnItems[] += {"FirstAidKit"}; //Adds additional FAK
};

/*
	Original RespawnItems[] array in config viewer:
	RespawnItems[] = {"FirstAidKit"};

	Modified RespawnItems[] array in config viewer:
	RespawnItems[] = {"FirstAidKit","FirstAidKit"};
*/

Order of Precedence

Order of operations, also called operator precedence, is a set of rules specifying which procedures should be performed first in a mathematical expression.

Precedence Overview

  • Highest precedence means highest priority
  • Associativity is (then) done from left to right, for example 3 + 5 + 8 will be processed as ((3 + 5) + 8)
Precedence Type of Operator Examples
11

Nular operators (commands with no arguments):

  • commandName
10

Unary operators (commands with 1 argument):

  • commandName a
9 Hash-select operator
8 Power operator
7
6
5 N/A
4

Binary operators (commands with 2 arguments):

  • a commandName b
3
2 Logical and operator
1 Logical or operator


Examples

Input Process Comment
1 + 2 * 3
1 + (2 * 3)
result equals 7, and not 9 (see also PEMDAS)
sleep 10 + random 20
(sleep 10) + random 20
sleep 10 will return Nothing, then + random 20 will be calculated but not used.

sleep (10 + random 20) should be used instead


See Also