exitWith: Difference between revisions
Jump to navigation
Jump to search
Lou Montana (talk | contribs) m (Some wiki formatting) |
Lou Montana (talk | contribs) m (Some wiki formatting) |
||
Line 121: | Line 121: | ||
[[exitWith]] cannot be used in event handlers with override ability to simply exit with override value. The following is incorrect: | [[exitWith]] cannot be used in event handlers with override ability to simply exit with override value. The following is incorrect: | ||
<sqf>// INCORRECT USAGE | <sqf>// INCORRECT USAGE | ||
onMapSingleClick {if (!isServer) exitWith {true}};</sqf> | onMapSingleClick { if (!isServer) exitWith { true } };</sqf> | ||
The override value must be returned in the main scope of EH, but since it is exited with [[exitWith]], it never happens. The correct way in this case would be: | The override value must be returned in the main scope of EH, but since it is exited with [[exitWith]], it never happens. The correct way in this case would be: | ||
< | <sqf>// CORRECT USAGE | ||
onMapSingleClick {call {if (!isServer) exitWith {true}}};</ | onMapSingleClick { call { if (!isServer) exitWith { true } } };</sqf> | ||
[[exitWith]] will exit current [[call]] scope only and override value therefore will appear in the main scope of the EH, right where we want it. | [[exitWith]] will exit current [[call]] scope only and override value therefore will appear in the main scope of the EH, right where we want it. | ||
</dd> | </dd> | ||
</dl> | </dl> |
Revision as of 16:04, 13 May 2022
Description
- Description:
- Exits the current code scope. Often used for exiting do, for, count, forEach or the whole script.
- Groups:
- Program Flow
Syntax
Examples
- Example 1:
- systemChat "start"; private _condition = true; if (_condition) then { if (true) exitWith { systemChat "exiting if _condition scope"; }; systemChat "never shown"; }; systemChat "exiting #1 worked"; if (true) exitWith { systemChat "exiting the main scope = leaving the whole script"; }; systemChat "never shown - the script has already ended";
- Example 2:
- for "_j" from 1 to 10 do { systemChat format ["%1", _j]; // the for loop will cease and code execution will continue after the end of the loop if (_j == 5) exitWith { systemChat "5 is enough"; }; }; systemChat "Complete";
- Example 3:
- Most loops will also terminate when their scope is exited. To exit and terminate scopes which are called every frame such as onEachFrame and waitUntil use the following examples:
- Example 4:
- Example 5:
Additional Information
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
- Posted on May 28, 2010 - 22:15
- Roehre
- Since Arma 2 uses Blocks in FSM as any ordinary Handle like while, for etc. in Scripts, ExitWith also only closes the Block in the FSM.
- Posted on August 04, 2013 - 12:20
- Killzone_Kid
- The command will exit the current scope - no ifs no buts. If the current scope is a loop, it will exit the loop. If the current scope is the main body of a script, it will exit the script. For more understanding of scopes and exitWith have a look at this resource.
- Posted on March 10, 2016 - 08:31 (UTC)
- Killzone Kid
-
exitWith cannot be used in event handlers with override ability to simply exit with override value. The following is incorrect:
The override value must be returned in the main scope of EH, but since it is exited with exitWith, it never happens. The correct way in this case would be: exitWith will exit current call scope only and override value therefore will appear in the main scope of the EH, right where we want it.
Categories:
- Scripting Commands
- Introduced with Armed Assault version 1.00
- ArmA: Armed Assault: New Scripting Commands
- ArmA: Armed Assault: Scripting Commands
- Arma 2: Scripting Commands
- Arma 2: Operation Arrowhead: Scripting Commands
- Take On Helicopters: Scripting Commands
- Arma 3: Scripting Commands
- Command Group: Program Flow