breakOut: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
mNo edit summary
m (Text replacement - "<sqf>([^↵][^<]*↵[^<]*)<\/sqf>" to "<sqf> $1 </sqf>")
 
(29 intermediate revisions by the same user not shown)
Line 19: Line 19:


|descr= Breaks out of the [[Variables#Scopes|scope]] with given '''name'''.
|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}}
* 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 '''Example 3'''.
* If multiple scopes with the same '''name''' exist, the command will break out the nearest scope. See {{Link|#Example 3}}.


|s1= [[breakOut]]  name
|s1= [[breakOut]]  name


|p1= name: [[String]] - Name of the scope which was previously set with [[scopeName]]. {{ic|""}} will exit the current scope.
|p1= name: [[String]] - name of the scope which was previously set with [[scopeName]]. <sqf inline>""</sqf> will exit the current scope (see also [[exitWith]])


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


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


|p21= value: [[Anything]] - A value to return
|s2since= arma3 1.48


|p22= name: [[String]] - Name of the scope which was previously set with [[scopeName]]. {{ic|""}} will exit the current scope.
|p21= value: [[Anything]] - a value to return


|r2= [[Anything]] - Will return '''value'''
|p22= name: [[String]] - name of the scope which was previously set with [[scopeName]]. <sqf inline>""</sqf> will exit the current scope (see also [[exitWith]])


|x1= <code>[[scopeName]] "main";
|r2= [[Anything]] - will return '''value'''
[[while]] {[[true]]} [[do]] {
 
[[scopeName]] "loop1";
|x1= <sqf>
[[while]] {[[true]]} [[do]] {
scopeName "main";
[[scopeName]] "loop2";
while { true } do {
[[if]] (condition1) [[then]] {[[breakTo]] "main"}; {{cc|Breaks all scopes and return to "main"}}
scopeName "loop1";
[[if]] (condition2) [[then]] {[[breakOut]] "loop2"}; {{cc|Breaks scope named "loop2"}}
while {true} do {
[[sleep]] 1;
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>
</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>
}; // call returns 123
</sqf>


|x3= <code>[[call]] {
|x3= <sqf>
[[scopeName]] "Main"; {{cc|Parent Main}}
call {
[[call]] {
scopeName "Main"; // Parent Main
[[scopeName]] "Main"; {{cc|Child Main}}
call {
"String" [[breakOut]] "Main"; {{cc|Will break out of child main and return "String" to parent main}}
scopeName "Main"; // Child Main
"String" breakOut "Main"; // Will break out of child main and return "String" to parent main
};
};
};
};
</code>
</sqf>


|seealso= [[scopeName]], [[breakTo]], [[exitWith]]
|seealso= [[scopeName]] [[breakTo]] [[exitWith]]
}}
}}

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