# 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 ```sqf _arr = [42, "hello", true]; _arr params ["_num", "_str", "_flag"]; // _num = 42, _str = "hello", _flag = true ``` ### With defaults ```sqf _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 ```sqf _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 ```sqf _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 ```sqf [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](call.md) — execute code with arguments - [spawn](spawn.md) — async with arguments - [typeName](typeName.md) — runtime type checking - [select](select.md) — manual array element access