canSuspend: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Some wiki formatting)
m (Some wiki formatting)
Line 6: Line 6:
|gr2= Program Flow
|gr2= Program Flow


|descr= Returns [[true]] if [[sleep]], [[uiSleep]] or [[waitUntil]] commands can be used in current scope. Usually when suspension is not allowed but used, for example when code is executed in [[Scheduler#Unscheduled_Environment|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.
|descr= 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 [[Scheduler#Unscheduled Environment|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.


{{Feature | Informative |The definition of [[Scheduler#Scheduled_Environment|scheduled]] and [[Scheduler#Unscheduled_Environment|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 [[Scheduler#Scheduled_Environment|scheduled]] (i.e. added to the [[Scheduler|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]]. }}
{{Feature|informative|
The definition of [[Scheduler#Scheduled Environment|scheduled]] and [[Scheduler#Unscheduled Environment|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 [[Scheduler#Scheduled_Environment|scheduled]] (i.e. added to the [[Scheduler|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]].
}}


|s1= [[canSuspend]]
|s1= [[canSuspend]]
Line 15: Line 21:


|x1= <sqf>
|x1= <sqf>
onEachFrame  
onEachFrame
{
{
systemChat str canSuspend; // false
systemChat str canSuspend; // false
[] spawn { hint str canSuspend }; // true
0 spawn { hint str canSuspend }; // true
onEachFrame {};
onEachFrame {};
};
};
Line 25: Line 31:
|x2= Make sure the function code is always spawned even when called:
|x2= Make sure the function code is always spawned even when called:
<sqf>
<sqf>
sleepingCode =  
private _sleepingCode =
{
{
if (!canSuspend) exitWith { _this spawn sleepingCode };
if (!canSuspend) exitWith { _this spawn sleepingCode };
Line 32: Line 38:
};
};


5 call sleepingCode;
5 call _sleepingCode;
</sqf>
</sqf>


|seealso= [[sleep]] [[uiSleep]] [[waitUntil]] [[call]] [[spawn]] [[execVM]] [[isRemoteExecuted]] [[isRemoteExecutedJIP]] [[remoteExecutedOwner]] [[isUIContext]] [[isGamePaused]] [[isGameFocused]]
|seealso= [[sleep]] [[uiSleep]] [[waitUntil]] [[call]] [[spawn]] [[execVM]] [[isRemoteExecuted]] [[isRemoteExecutedJIP]] [[remoteExecutedOwner]] [[isUIContext]] [[isGamePaused]] [[isGameFocused]]
}}
}}

Revision as of 18:14, 15 March 2024

Hover & click on the images for description

Description

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.
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.
Groups:
Program Flow

Syntax

Syntax:
canSuspend
Return Value:
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;

Additional Information

See also:
sleep uiSleep waitUntil call spawn execVM isRemoteExecuted isRemoteExecutedJIP remoteExecutedOwner isUIContext isGamePaused isGameFocused

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note