exitWith – Talk
Jump to navigation
Jump to search
(what does it exit?) |
No edit summary |
||
Line 18: | Line 18: | ||
::<code>for "_j" from 1 to 10 do <br> {<br> player sideChat format["%1",_j];<br> if (_j==5) exitWith {player sideChat "5 is enough"};<br> };<br> player sideChat "Complete";</code> | ::<code>for "_j" from 1 to 10 do <br> {<br> player sideChat format["%1",_j];<br> if (_j==5) exitWith {player sideChat "5 is enough"};<br> };<br> player sideChat "Complete";</code> | ||
::--[[User:Kronzky|Kronzky]] 16:37, 7 May 2007 (CEST) | ::--[[User:Kronzky|Kronzky]] 16:37, 7 May 2007 (CEST) | ||
'''Note''' this command cannot be used as a way to return a value in a function! | |||
Not correct: | |||
<code>myFunc = { | |||
if (alive player) exitwith {true}; | |||
false | |||
};</code> | |||
Good: | |||
<code>anotherFunc = { | |||
_return = objnull; | |||
{ | |||
if (alive _x) exitwith {_return = _x}; // here we use it just to break out of the loop | |||
} foreach _array; | |||
_return | |||
}; | |||
</code> --[[User:Doolittle|Doolittle]] 06:06, 26 August 2007 (CEST) |
Revision as of 05:06, 26 August 2007
It seems this command exits the current "scope" (is this the correct term?), rather than the current script file. Is this correct?
Example code, started using execVM:
<stuff> for "_j" from 1 to _value do { <stuff> if (<exit condition>) exitWith {player sideChat "Cancelled"}; }; player sideChat "Complete";
If the exit condition is true, both sideChats are executed. Any comments? Or am I just stating the obvious? :) --Ceeeb 10:04, 7 May 2007 (CEST)
- Seems so, yes. Good find. --raedor 12:33, 7 May 2007 (CEST)
- Yes, it only exits the current level (or "block" or "scope" or whatever). So that behaviour would be expected.
- Do this, for example, and it should become a bit more obvious:
for "_j" from 1 to 10 do
{
player sideChat format["%1",_j];
if (_j==5) exitWith {player sideChat "5 is enough"};
};
player sideChat "Complete";- --Kronzky 16:37, 7 May 2007 (CEST)
Note this command cannot be used as a way to return a value in a function!
Not correct:
myFunc = {
if (alive player) exitwith {true};
false
};
Good:
anotherFunc = {
_return = objnull;
{
if (alive _x) exitwith {_return = _x}; // here we use it just to break out of the loop
} foreach _array;
_return
};
--Doolittle 06:06, 26 August 2007 (CEST)