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

call

Category

Code Execution

Arity

Unary or Binary.

// Unary: no arguments
call { code }

// Binary: with arguments
<args> call { code }
<args> call <codeVariable>

Description

Executes a code block synchronously and returns its result. The calling fiber blocks until the code completes. If used in binary form, the left-hand value becomes _this inside the code block.

call cannot suspendsleep, await, and other suspending commands will throw an error if used inside call-executed code.

How It Works

This is a compiler-level construct with a dedicated opcode. The compiler inlines the call:

  1. Pushes args (if binary) to the stack.
  2. Jumps into the code block.
  3. The code block's last expression is the return value.

Unlike spawn, call does not create a new fiber — it runs in the current fiber's context.

Usage

Unary call (no args)

_result = call { 1 + 2; };             // returns 3

call {
    systemChat "Hello";
    doWork();
};

Binary call (with args)

_result = [10, 20] call {
    params ["_a", "_b"];
    _a + _b                              // 30
};

Call with code variable

_myFunc = compile "(_this select 0) * 2";
_result = 5 call _myFunc;               // 10

_double = { _this * 2 };
_result = 7 call _double;               // 14

Inline condition

if (call { _complexCheck() }) then {
    doThing();
};

vs spawn

// call — synchronous, no sleep allowed
_result = call { 1 + 2 };

// spawn — asynchronous, sleep allowed, returns ScriptHandle
_handle = spawn { sleep 1; _result = 1 + 2; };

Limitations

  • Cannot use sleep, await, or any suspending command.
  • Runs in caller's scheduler/fiber context.
  • Long-running code in call blocks the fiber — use spawn for heavy work.

Thread Safety

Inherits the caller's scheduler. Safe within same scheduler. Cross-scheduler calls require spawnOn.

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