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 (Formatting)
Line 10: Line 10:


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



Revision as of 05:11, 9 December 2020

-wrong parameter ("Arma") defined!-1.00
Hover & click on the images for description

Description

Description:
Breaks the code execution out of scope {} named name. nil is returned. Scope name can be assigned using scopeName command.
An unknown scopeName name will cause the script error Generic error in expression
An empty scopeName name will leave the current scope immediate



Since Arma 3 v1.47, breakOut can be used to return a value. It is the closest SQF comes to having "return"-like operation.
Groups:
Program Flow

Syntax

Syntax:
breakOut name
Parameters:
name: String - name of the scope (previously set with scopeName)
Return Value:
Nothing

Alternative Syntax

Syntax:
value breakOut name Template:since
Parameters:
value: Anything - a value to return
name: String - name of the scope (previously set with scopeName)
Return Value:
Anything

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

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

Notes

Bottom Section

Posted on August 27, 2015 - 16:09 (UTC)
Polaris
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: 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 }; }; 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.