Skip to content
ffredyk edited this page Jul 23, 2026 · 1 revision

params

Category

Compiler Construct

Description

params is a compiler-level construct (not a runtime-registered command) that destructures an array into named local variables. It is the primary way to unpack function arguments in SQ#.

Supports:

  • Simple variable binding
  • Default values for missing elements
  • Type-checked binding

How It Works

The compiler inlines params into _this select N expressions with optional type checks at compile time. There is no runtime params command — it is entirely resolved during compilation.

Usage

Basic destructuring

_arr = [42, "hello", true];
_arr params ["_num", "_str", "_flag"];
// _num = 42, _str = "hello", _flag = true

With defaults

_arr = [42];
_arr params ["_num", ["_opt", 99]];
// _num = 42, _opt = 99 (default used since _arr has < 2 elements)

_arr = [42, 77];
_arr params ["_num", ["_opt", 99]];
// _num = 42, _opt = 77 (default NOT used — value exists)

Type-checked

_arr = [42, "player", true];
_arr params [["_num", "number"], ["_name", "string"], ["_alive", "boolean"]];
// Compiler generates type assertions — throws if types don't match

In function context

_myFunc = {
    params ["_a", "_b", ["_c", 0]];
    _a + _b + _c
};

_result = [10, 20] call _myFunc;     // 30 (_c defaults to 0)
_result = [10, 20, 5] call _myFunc;  // 35

With _this in spawn/call

[100, "player"] spawn {
    params ["_hp", "_name"];
    systemChat f"{_name} HP: {_hp}";
};

Type Check Options

Syntax Behavior
"_var" Bind variable, no type check
["_var", defaultValue] Bind with fallback
["_var", "type"] Bind with type assertion
["_var", defaultValue, "type"] Bind with fallback AND type check

Thread Safety

Compile-time only — no runtime overhead. Safe everywhere.

See Also

  • call — execute code with arguments
  • spawn — async with arguments
  • typeName — runtime type checking
  • select — manual array element access

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