exitWith – Talk

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Observation on the scope of this command.)
 
m (Text replacement - "<code>" to "<code style="display: block">")
 
(10 intermediate revisions by 7 users not shown)
Line 1: Line 1:
It seems this command exits the current "scope", rather than the current script file. Is this correct?
It seems this command exits the current "scope" (is this the correct term?), rather than the current script file. Is this correct?


Code, started using [[execVM]]:  
Example code, started using [[execVM]]:  
  <stuff>
  <stuff>
  for "_j" from 1 to _value do  
  for "_j" from 1 to _value do  
Line 8: Line 8:
   if (<exit condition>) exitWith {player sideChat "Cancelled"};
   if (<exit condition>) exitWith {player sideChat "Cancelled"};
   };
   };
sleep 2;
  player sideChat "Complete";
  player sideChat "Complete";


Both sideChats are executed. Any comments? Or am I just stating the obvious? :)  --[[User:Ceeeb|Ceeeb]] 10:04, 7 May 2007 (CEST)
If the exit condition is true, both sideChats are executed. Any comments? Or am I just stating the obvious? :)  --[[User:Ceeeb|Ceeeb]] 10:04, 7 May 2007 (CEST)
 
:Seems so, yes. Good find. --[[User:Raedor|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:
::<code style="display: block">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)

Latest revision as of 11:53, 11 January 2023

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)