canSuspend: Difference between revisions
Jump to navigation
Jump to search
Lou Montana (talk | contribs) m (Text replacement - " *\| *([Cc]omments|COMMENTS|Game|[Gg]ame [Nn]ame( +[0-9])?|Game [Vv]ersion( +[0-9])?|Game Version \(number surrounded by NO SPACES\)|Arguments in MP|Multiplayer Arguments( \("local" or "global"\))?|Effects|Execution|Effects? in MP|M...) |
Lou Montana (talk | contribs) m (Fix the fix) |
||
(32 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
{{ | {{RV|type=command | ||
| arma3 |= | |game1= arma3 | ||
|version1= 1.58 | |||
|gr2= Program Flow | |gr2= Program Flow | ||
|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]]. | |||
}} | |||
|s1= [[canSuspend]] | |||
|r1= [[Boolean]] | |||
| | |x1= <sqf> | ||
onEachFrame | |||
{ | |||
systemChat str canSuspend; // false | |||
0 spawn { hint str canSuspend }; // true | |||
onEachFrame {}; | |||
}; | |||
</sqf> | |||
|x2= Make sure the function code is always spawned even when called: | |||
| | <sqf> | ||
private _sleepingCode = | |||
{ | { | ||
if (!canSuspend) exitWith { _this spawn _sleepingCode }; | |||
sleep _this; | |||
hint ("slept " + str _this); | |||
}; | }; | ||
5 | 5 call _sleepingCode; | ||
</sqf> | |||
|seealso= [[sleep]] [[uiSleep]] [[waitUntil]] [[call]] [[spawn]] [[execVM]] [[isRemoteExecuted]] [[isRemoteExecutedJIP]] [[remoteExecutedOwner]] [[isUIContext]] [[isGamePaused]] [[isGameFocused]] | |||
| [[sleep]] | |||
}} | }} | ||
Latest revision as of 21:47, 17 March 2024
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.
- 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:
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