Arma 3 Scripting

Topic in Scripting

Order of Precedence

Also available as Markdown and JSON, or read the original wiki page.

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

Note

  • 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
- Variables
- Values
- () / [] / {} / "" / '' -enclosed expressions
10 Unary operators (commands with 1 argument):
- commandName a
* +a
- -a
- +array
- ! b
- not b
9 Hash-select operator - array # index
8 Power operator - a ^ b
7 - Number multiplication, division and remainder
- atan2
- Config access (/)
* a * b
- a / b
- a % b
- a mod b
- a / b
- a atan2 b
6 - Number addition and subtraction
- Array addition and subtraction
- String addition
- min and max commands
* a + b
- a - b
- arr1 + arr2
- arr1 - arr2
- str1 + str2
- a min b
- a max b
5 - else (if-then-else structure) N/A
4 Binary operators (commands with 2 arguments):
- a commandName b
- setDir
- switch colon (:)
3 - == and != comparisons
- Number comparisons
- Config access (>>)
- a == b
- a != b
- a > b
- a < b
- a >= b
- a <= b
- config >> name
2 Logical and operator - &&
- and
1 Logical or operator - ||
- or

Examples

Input Process Comment
sqf
1 + 2 * 3
sqf
1 + (2 * 3)
result equals 7, and not 9 (see also PEMDAS)
sqf
sleep 10 + random 20
sqf
(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