Arma 3 Scripting

Command in Program Flow

canSuspend

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

Description

Returns true if sleep, uiSleep or waitUntil commands can be used in the current scope. Usually when suspension is not allowed but used, for example when code is executed in unscheduled environment, the script engine would ignore any suspension command and throw error: "Suspending not allowed in this context". Using canSuspend command allows to detect the correct environment for the code.

Note

The definition of scheduled and unscheduled environment is not the same as whether or not the script execution can or cannot be suspended. For example while .sqs and .fsm scripts are scheduled (i.e. added to the scheduler: diag_activeSQSScripts, diag_activeMissionFSMs), they cannot use sleep or be suspended like execVM or spawn scripts can, therefore canSuspend for these types of scripts will return false.

Syntax

canSuspend

Returns: Boolean

Examples

Example 1

onEachFrame
{
    systemChat str canSuspend;            // false
    0 spawn { hint str canSuspend };    // true
    onEachFrame {};
};

Example 2

Make sure the function code is always spawned even when called:

private _sleepingCode =
{
    if (!canSuspend) exitWith { _this spawn _sleepingCode };
    sleep _this;
    hint ("slept " + str _this);
};

5 call _sleepingCode;

See also

sleep · uiSleep · waitUntil · call · spawn · execVM · isRemoteExecuted · isRemoteExecutedJIP · remoteExecutedOwner · isUIContext · isGamePaused · isGameFocused