Benargee/Sandbox – User

From Bohemia Interactive Community
Jump to navigation Jump to search
mNo edit summary
(Blanked the page)
Line 1: Line 1:
{{BenargeeSandbox|= Comments
____________________________________________________________________________________________


| arma3dev |= Game name
|999|= Game version
____________________________________________________________________________________________
| Checks if the given parameter matches any [[case]]. If so, the code block of that case will be executed. After that the switch ends so no further cases will be checked.<br>
<br>
If a case has no code block, the code of the next case will automatically be executed. This makes it possible to formulate a logical '''"or"''' for cases which otherwise would contain the exact same code. (See example 4 below)<br>
The [[default]] block will only be executed if no case matches, no matter at which position inside the switch it is.<br>
<br>
''switch'' returns whatever the return value of the case block is. |= Description
____________________________________________________________________________________________
| switch '''do''' block |= Syntax
|p1= switch: [[Switch Type]] |= Parameter 1
|p2= block: [[Code]] |= Parameter 2
| [[Anything]] |= Return value
____________________________________________________________________________________________
|x1= <code>[[switch]] (_a) [[do]] { [[case]] 1 : { /*...code...*/ }; [[case]] 2 : { /*...code...*/ }; [[default]] { /*...code...*/ }; };</code>
<br>
<code>[[switch]] (_condition) [[do]] {
    [[case]] 1: { [[hint]] "1" };
    [[case]] 2: { [[hint]] "2" };
    [[default]] { [[hint]] "default" };
};</code>
<br>
<code>[[switch]] (_condition) [[do]] {
    [[case]] "string1";
    [[case]] "string2": { [[hint]] "string1 or string2" };
    [[case]] "string3";
    [[case]] "string4": { [[hint]] "string3 or string4" };
    [[default]] { [[hint]] "default" };
};</code> |= Example 1
|x2= <code>_color = [[switch]] ([[side]] [[player]]) [[do]] {
    [[case]] [[west]]: { "ColorGreen" };
    [[case]] [[east]]: { "ColorRed" };
};</code>
|x3= <code>_fn_moveForward = { /*...code...*/ };
_fn_moveBackward = { /*...code...*/ };
_fn_invalidKey = { /*...code...*/ };
[[switch]] [[true]] [[do]] {
    [[case]] (_dikCode [[in]] [[actionKeys]] "MoveForward"): _fn_moveForward;
    [[case]] (_dikCode [[in]] [[actionKeys]] "MoveBackward"): _fn_moveBackward;
    [[default]] _fn_invalidKey;
};</code> |= Example 3
|x4= <code>[[switch]] _var [[do]] {
    [[case]] "0";
    [[default]] { [[hint]] [[str]] ["default", _var] };
    [[case]] "3": { [[hint]] [[str]] ["3", _var] };
    [[case]] "1";
    [[case]] "4";
    [[case]] "2": { [[hint]] [[str]] ["2", _var] };
};</code>
<pre>_var = "0"; //-> ["3", "0"]
_var = "1"; //-> ["2", "1"]
_var = "2"; //-> ["2", "2"]
_var = "3"; //-> ["3", "3"]
_var = "4"; //-> ["2", "4"]
_var = "5"; //-> ["default", "5"]</pre> |= Example 4
| [[Control Structures]], [[a:b]], [[case]], [[default]] |= See also
}}

Revision as of 22:28, 14 December 2014