breakOut: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(alt syntax, example)
m (Text replacement - "<sqf>([^↵][^<]*↵[^<]*)<\/sqf>" to "<sqf> $1 </sqf>")
 
(77 intermediate revisions by 7 users not shown)
Line 1: Line 1:
{{Command|= Comments
{{RV|type=command
____________________________________________________________________________________________


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


|1.00|= Game version
|game2= arma2
____________________________________________________________________________________________
|version2= 1.00


| Breaks block out of scope named name. Nil is returned.
|game3= arma2oa
|version3= 1.50


Scope name can be assigned using [[scopeName]] command.
|game4= tkoh
|version4= 1.00


<br><br>
|game5= arma3
Since Arma 3 v1.47, [[breakOut]] can be used to return 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]] |= Parameter 1
|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]] |= Return value
|s1= [[breakOut]] name


| s2= value '''breakOut''' name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (''since Arma 3 v1.47'') |= Syntax
|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]] |= Parameter 1
|r1= [[Nothing]]
|p22= name: [[String]] |= Parameter 1


| r2= [[Anything]] |= Return value
|s2= value [[breakOut]] name


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


|x2= <code>[[call]] {
|x2= <sqf>
[[scopeName]] "main";  
call {
[[call]] {
scopeName "main";
123 [[breakOut]] "main"
call {
123 breakOut "main"
};
};
345
345
}; // call returns 123</code> |= Example 2
}; // call returns 123
____________________________________________________________________________________________
</sqf>


| [[scopeName]], [[breakTo]], [[exitWith]] |= See also
|x3= <sqf>
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
};
};
</sqf>


|seealso= [[scopeName]] [[breakTo]] [[exitWith]]
}}
}}
<h3 style="display:none">Notes</h3>
<dl class="command_description">
<!-- Note Section BEGIN -->
<dd class="notedate">Posted on 19 Aug, 2008
<dt class="note">'''[[User:Alef|alef]]'''<dd class="note">
When "name" is nil, the command is ignored.<br>
When "name" is an undefined scope name or "", the script quits current scope.
<code>if (true) then {
hint "1";
breakOut nil;
hint "2";
}; //result "2"
if (true) then {
hint "1";
breakOut "";
hint "2";
}; //result "1"
if (true) then {
hint "1";
breakOut "dskfhdsklfh";
hint "2";
}; //result "1"
</code>
<!-- Note Section END -->
</dl>
<h3 style="display:none">Bottom Section</h3>
[[Category:Scripting Commands|BREAKOUT]]
[[Category:Scripting Commands ArmA|BREAKOUT]]
[[Category:Scripting Commands ArmA2|BREAKOUT]]
[[Category:Command_Group:_Variables|{{uc:{{PAGENAME}}}}]]
[[Category:Command_Group:_Program_Flow|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands ArmA2|{{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