Skip to content

Language Guide

ffredyk edited this page Jul 23, 2026 · 1 revision

Language Guide

Complete guide to SQ# syntax, variables, operators, and core language features.

Syntax Basics

Terminators

Statements end with ; (preferred) or ,:

_x = 5;
_y = 10;
_x = 5, _y = 10;  // also valid

Comments

// Line comment
/* Block comment
   spanning multiple lines */

Identifiers

  • Local variables: start with __myVar, _count, _x
  • Global variables: no _ prefix — myGlobal, SCORE
  • Case-insensitive: _myVar and _MYVAR are the same variable
  • Unicode letters allowed: _žlutý, _переменная

Assignment

Only = operator. No +=, -=, ++, --:

_x = 5;
_y = _x + 10;
_arr = [1, 2, 3];

Variables

Local Variables

private _local = 42;           // explicit declaration
_local = 42;                   // implicit (first assignment declares)
private _a, _b, _c;            // multiple declaration (all nil)

Global Variables

myGlobal = 100;                // bare name = global (SQF style)
global HIGH_SCORE = 999;       // explicit global keyword

nil Deletes Variables

Assigning nil to a variable deletes it (matches SQF behavior):

_myVar = 42;
_myVar = nil;                  // _myVar no longer exists!
isNil "_myVar";                // true

nil is still valid in arrays and comparisons:

_arr = [1, nil, 3];            // nil as array element — fine
if (_arr select 1 == nil) then { ... };  // comparison works

Type Annotations (Optional)

private _hp: number = 100;     // typed local
private _name: string = "";    // optional, for clarity/tooling

Literals

Type Examples
Number 42, 3.14, -5, 1.5e10
String "hello", 'hello', @"C:\path"
Boolean true, false
Nil nil
Array [1, 2, 3], ["a", "b"]
Code { _x * 2 }, { sleep 1; }

Operators

Arithmetic

Op Arity Description
+ binary Addition / string concatenation
- binary/unary Subtraction / negation
* binary Multiplication
/ binary Division (zero divisor → error)
% binary Modulo
^ binary Power (exponentiation)
min binary Smaller of two
max binary Larger of two
_result = 3 + 4;               // 7
_result = 10 / 3;              // 3.333...
_result = 2 ^ 8;               // 256
_result = 5 min 3;             // 3

Comparison

Op Description
== Equal (strict, no type coercion)
!= Not equal
< Less than
> Greater than
<= Less than or equal
>= Greater than or equal
if (_hp <= 0) { handleDeath(); };
if (_name == "player") { ... };
"hello" == "HELLO";            // false (case-sensitive, unlike SQF!)

Logical (Short-Circuit)

Op Description
! NOT
&& AND (short-circuit)
|| OR (short-circuit)
if (_alive && _hp > 50) { attack(); };  // _hp only checked if _alive
_flag = !_done;

Operator Precedence

Higher number = higher priority. Equal precedence → left-to-right.

Prec Category Operators
11 Values, brackets literals, (), [], {}, variables
10 Unary -x, !flag, count _arr, str _val
9 Hash-select _arr # index
8 Power a ^ b
7 Mul/Div/Mod *, /, %
6 Add/Sub/Min/Max +, -, min, max
5 else else
4 Binary commands select, pushBack, set, resize
3 Comparisons ==, !=, <, >, <=, >=
2 AND &&
1 OR ||
// Precedence in action:
_result = 3 + 4 * 2;           // 11 (not 14) — * before +
_flag = _a > 0 && _b < 10;     // comparisons before && — works as expected

Command Arity

Every command takes exactly one expression on its right side:

Arity Pattern Example
Nular cmd — no operands nil, player, true
Unary cmd <right> count _arr, str _val
Binary <left> cmd <right> _a + _b, _arr select 0

Commands needing 3+ parameters use an array on the right:

_arr set [idx, val]            // 2 params packed into array
spawnOn ["AI", { code }]       // scheduler name + code packed into array

String Literals

// Double-quoted (escape sequences supported)
_name = "Hello\nWorld";        // \n = newline

// Single-quoted (no escapes except '')
_path = 'C:\Users\Name';       // backslashes are literal

// Verbatim (no escapes at all)
_path = @"C:\Users\Name\Documents";

// Multi-line
_text = """
    Line 1
    Line 2
    """;

// Interpolation (f-strings)
_msg = f"Player {_name} has {_hp} HP";

Brackets

Bracket Purpose
() Grouping, precedence, command arguments
[] Array literals, array-form command args
{} Code blocks
"" / '' String literals

See Also

SQ# Wiki

Home

Engine Docs

Migration

Commands

Value Constructors

Arithmetic

Comparison

Logic

Array

String

Math

Random

Type & Introspection

HashMap

Code Execution

Concurrency

Scheduler

Thread Safety

Error

Output

Time

Multiplayer

Compiler

Clone this wiki locally