breakOut: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(Removed note by `alef` as it was no longer true and worked correct findings into an important and an informative note inside of the description)
m (Text replacement - "<sqf>([^↵][^<]*↵[^<]*)<\/sqf>" to "<sqf> $1 </sqf>")
 
(54 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Command|Comments=
{{RV|type=command
____________________________________________________________________________________________


| arma |Game name=
|game1= arma1
|version1= 1.00


|gr1= Program Flow |GROUP1=
|game2= arma2
|version2= 1.00


|1.00|Game version=
|game3= arma2oa
____________________________________________________________________________________________
|version3= 1.50


| Breaks the code execution out of scope {} named ''name''. [[nil]] is returned. Scope name can be assigned using [[scopeName]] command.
|game4= tkoh
{{Important|An unknown [[scopeName]] name will cause a `Generic error in expression` script error}}
|version4= 1.00
{{Informative|An empty [[scopeName]] name will leave the current scope immediate}}


<br><br>
|game5= arma3
Since Arma 3 v1.47, [[breakOut]] can be used to return a ''value''. It is the closest SQF comes to having "return"-like operation. |DESCRIPTION=
|version5= 0.50
____________________________________________________________________________________________


| '''breakOut''' name |SYNTAX=
|gr1= Program Flow


|p1= name: [[String]] - name of the scope (previously set with [[scopeName]]) |PARAMETER1=
|descr= Breaks out of the [[Variables#Scopes|scope]] with given '''name'''.
* An unknown [[scopeName]] name will cause the script error {{hl|Generic error in expression}}
* If multiple scopes with the same '''name''' exist, the command will break out the nearest scope. See {{Link|#Example 3}}.


| [[Nothing]] |RETURNVALUE=
|s1= [[breakOut]] name


|s2= value '''breakOut''' name {{since|arma3|1.47|y}} |SYNTAX2=
|p1= name: [[String]] - name of the scope which was previously set with [[scopeName]]. <sqf inline>""</sqf> will exit the current scope (see also [[exitWith]])


|p21= value: [[Anything]] - a value to return |PARAMETER21=
|r1= [[Nothing]]


|p22= name: [[String]] - name of the scope (previously set with [[scopeName]])  |PARAMETER22=
|s2= value [[breakOut]] name


|r2= [[Anything]] |RETURNVALUE2=
|s2since= arma3 1.48


|x1= <code>[[scopeName]] "main";
|p21= value: [[Anything]] - a value to return
[[while]] {[[true]]} [[do]] {
 
[[scopeName]] "loop1";
|p22= name: [[String]] - name of the scope which was previously set with [[scopeName]]. <sqf inline>""</sqf> will exit the current scope (see also [[exitWith]])
[[while]] {[[true]]} [[do]] {
 
[[scopeName]] "loop2";
|r2= [[Anything]] - will return '''value'''
[[if]] (condition1) [[then]] {[[breakTo]] "main"}; {{cc|Breaks all scopes and return to "main"}}
 
[[if]] (condition2) [[then]] {[[breakOut]] "loop2"}; {{cc|Breaks scope named "loop2"}}
|x1= <sqf>
[[sleep]] 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;
sleep 1;
};
};
</code> |EXAMPLE1=
</sqf>


|x2= <code>[[call]] {
|x2= <sqf>
[[scopeName]] "main";  
call {
[[call]] {
scopeName "main";
123 [[breakOut]] "main"
call {
123 breakOut "main"
};
};
345
345
}; {{cc|call returns 123}}</code> |EXAMPLE2=
}; // call returns 123
____________________________________________________________________________________________
</sqf>
 
| [[scopeName]], [[breakTo]], [[exitWith]] |SEEALSO=
}}
 
<h3 style="display:none">Notes</h3>
<h3 style="display:none">Bottom Section</h3>


<!-- CONTINUE Notes -->
|x3= <sqf>
<dl class="command_description">
call {
<dd class="notedate">Posted on August 27, 2015 - 16:09 (UTC)</dd>
scopeName "Main"; // Parent Main
<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"; //Parent Main
call {
call {
scopeName "Main"; //Child Main
scopeName "Main"; // Child Main
"String" breakOut "Main"; //Will break out of child main and return "String" to parent main
"String" breakOut "Main"; // Will break out of child main and return "String" to parent main
};
};
};
};
</code>
</sqf>
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 -->


[[Category:Scripting Commands Arma 2|{{uc:{{PAGENAME}}}}]]
|seealso= [[scopeName]] [[breakTo]] [[exitWith]]
[[Category:Scripting Commands Arma 2|{{uc:{{PAGENAME}}}}]]
}}
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Take On Helicopters|{{uc:{{PAGENAME}}}}]]

Latest revision as of 19:42, 3 September 2024

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 (see also exitWith)
Return Value:
Nothing

Alternative Syntax

Syntax:
value breakOut name
Parameters:
value: Anything - a value to return
name: String - name of the scope which was previously set with scopeName. "" will exit the current scope (see also exitWith)
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:
scopeName breakTo exitWith

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