exitWith: Difference between revisions
Jump to navigation
Jump to search
Killzone Kid (talk | contribs) No edit summary |
Killzone Kid (talk | contribs) No edit summary |
||
Line 65: | Line 65: | ||
<dt class="note">'''[[User:Roehre|Roehre]]''' | <dt class="note">'''[[User:Roehre|Roehre]]''' | ||
<dd class="note">Since ArmA2 uses Blocks in FSM as any ordinary Handle like [[while]], [[for]] etc. in Scripts, '''ExitWith''' also only closes the Block in the FSM. | <dd class="note">Since ArmA2 uses Blocks in FSM as any ordinary Handle like [[while]], [[for]] etc. in Scripts, '''ExitWith''' also only closes the Block in the FSM. | ||
<dd class="notedate">Posted on August 04, 2013 - 12:20 | |||
<dt class="note">'''[[User:Killzone_Kid|Killzone_Kid]]''' | |||
<dd class="note">I cannot dare to edit the description of this command as it was put by BIS dev himself. But I'd like to clarify the nature of this command to avoid any further confusion. 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 [http://killzonekid.com/arma-scripting-tutorials-scopes/ this resource]. | |||
<!-- Note Section END --> | <!-- Note Section END --> |
Revision as of 12:31, 4 August 2013
Description
- Description:
- If the result of condition is true, code is evaluated, and current block with result of code. It only exits the current scope. exitWith exits the execution of a loop defined by one of commands do, for, count or forEach. When you use exitWith not inside a loops, the behaviour is undefined - sometimes it may exit the script, sometimes some other scope, but this is not intended and designed behaviour of this command, and it is not guaranteed to work reliably. It exits the loop only, not the script.
- Groups:
- Uncategorised
Syntax
Examples
- Example 1:
if (_x>5) exitWith {echo "_x is too big"; _x}
When _x is greater than 5, outputs message and terminates code in current level with value of _x- Example 2:
for "_j" from 1 to 10 do { player sideChat format ["%1",_j]; if (_j==5) exitWith {player sideChat "5 is enough"}; }; player sideChat "Complete";
Only the "for" loop will exit when the exitWith condition has been fulfilled (not the whole script). Execution will continue after the end of the loop (player sideChat "Complete").- Example 3:
- Most loops will also terminate when their scope exited. To exit and terminate scopes which are called every frame such as onEachFrame and waitUntil use the following examples:
onEachFrame { if (!alive player) exitWith { onEachFrame {} } }
_time = time + 10; waitUntil { if (time > _time) exitWith { true } }
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
Notes
- Posted on May 28, 2010 - 22:15
- Roehre
- Since ArmA2 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
- I cannot dare to edit the description of this command as it was put by BIS dev himself. But I'd like to clarify the nature of this command to avoid any further confusion. 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.