breakOut: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "{{Inline code|" to "{{ic|")
m (formatting)
Line 1: Line 1:
{{RV|type=command
{{RV|type=command


| arma1
|game1= arma1
 
|version1= 1.00
 
|game2= arma2
 
|version2= 1.00
 
|game3= arma2oa
 
|version3= 1.51
 
|game4= tkoh
 
|version4= 1.00
 
|game5= arma3
 
|version5= 0.50


|gr1= Program Flow
|gr1= Program Flow


|1.00
|descr= Breaks out of the [[Variables#Scopes|scope]] with given '''name'''.
 
* An unknown [[scopeName]] name will cause the script error {{ic|Generic error in expression}}
| Breaks the code execution out of scope {} named ''name''. [[nil]] is returned. Scope name can be assigned using [[scopeName]] command.
* If multiple scopes with the same '''name''' exist, the command will break out the nearest scope. See '''Example 3'''.
{{Feature|important|An unknown [[scopeName]] name will cause the script error {{ic|Generic error in expression}}}}
{{Feature|Informative|An empty [[scopeName]] name will immediately leave the current scope}}
<br><br>
Since Arma 3 v1.47, [[breakOut]] can be used to return a ''value''. It is the closest SQF comes to having "return"-like operation.


| '''breakOut''' name
|s1= '''breakOut''' name


|p1= name: [[String]] - name of the scope (previously set with [[scopeName]])
|p1= name: [[String]] - Name of the scope which was previously set with [[scopeName]]. {{ic|""}} will exit the current scope.


| [[Nothing]]
|r1= [[Nothing]]


|s2= value '''breakOut''' name {{Since|arma3|1.47|y}}
|s2= value '''breakOut''' name {{Since|arma3|1.47|y}}


|p21= value: [[Anything]] - a value to return
|p21= value: [[Anything]] - A value to return


|p22= name: [[String]] - name of the scope (previously set with [[scopeName]])
|p22= name: [[String]] - Name of the scope which was previously set with [[scopeName]]. {{ic|""}} will exit the current scope.


|r2= [[Anything]]
|r2= [[Anything]] - Will return '''value'''


|x1= <code>[[scopeName]] "main";
|x1= <code>[[scopeName]] "main";
Line 48: Line 62:
}; {{cc|call returns 123}}</code>
}; {{cc|call returns 123}}</code>


|seealso= [[scopeName]], [[breakTo]], [[exitWith]]
|x3= <code>[[call]] {
}}
 
 
<!-- CONTINUE Notes -->
<dl class="command_description">
<dd class="notedate">Posted on August 27, 2015 - 16:09 (UTC)</dd>
<dt class="note">[[User:Polaris|Polaris]]</dt>
<dd class="note">
breakOut can still be used if multiple scopes share identical names. It will simply break out of the nearest scope that matches the name parameter you've used. For example:
<code>[[call]] {
[[scopeName]] "Main"; [[a / b|/]]/Parent Ma[[in]]
[[scopeName]] "Main"; [[a / b|/]]/Parent Ma[[in]]
[[call]] {
[[call]] {
Line 66: Line 70:
};
};
</code>
</code>
Therefore you are able to consistently reuse scope names such as "Main", "Child", "Primary", "Secondary", etc throughout functions without worrying about having to ensure you create unique names for each scope.
</dd>
</dl>
<!-- DISCONTINUE Notes -->


{{GameCategory|arma2|Scripting Commands}}
|seealso= [[scopeName]], [[breakTo]], [[exitWith]]
{{GameCategory|arma2|Scripting Commands}}
}}
{{GameCategory|arma3|Scripting Commands}}
{{GameCategory|tkoh|Scripting Commands}}

Revision as of 00:24, 30 March 2021

Hover & click on the images for description

Description

Description:
Breaks out of the scope with given name.
  • An unknown scopeName name will cause the script error Generic error in expression
  • If multiple scopes with the same name exist, the command will break out the nearest scope. See Example 3.
Groups:
Program Flow

Syntax

Syntax:
breakOut name
Parameters:
name: String - Name of the scope which was previously set with scopeName. "" will exit the current scope.
Return Value:
Nothing

Alternative Syntax

Syntax:
value breakOut name Template:Since
Parameters:
value: Anything - A value to return
name: String - Name of the scope which was previously set with scopeName. "" will exit the current scope.
Return Value:
Anything - Will return value

Examples

Example 1:
scopeName "main"; while {true} do { scopeName "loop1"; while {true} do { scopeName "loop2"; if (condition1) then {breakTo "main"}; // Breaks all scopes and return to "main" if (condition2) then {breakOut "loop2"}; // Breaks scope named "loop2" sleep 1; }; sleep 1; };
Example 2:
call { scopeName "main"; call { 123 breakOut "main" }; 345 }; // call returns 123
Example 3:
call { scopeName "Main"; //Parent Main call { scopeName "Main"; //Child Main "String" breakOut "Main"; //Will break out of child main and return "String" to parent main }; };

Additional Information

See also:
scopeNamebreakToexitWith

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