switch: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(example)
Line 20: Line 20:
|x2= <code>_color <nowiki>=</nowiki><br>switch (side player) do <br>{ <br>&nbsp;&nbsp;case west: {"ColorGreen"}; <br>&nbsp;&nbsp;case east: {"ColorRed"}; <br>};</code>
|x2= <code>_color <nowiki>=</nowiki><br>switch (side player) do <br>{ <br>&nbsp;&nbsp;case west: {"ColorGreen"}; <br>&nbsp;&nbsp;case east: {"ColorRed"}; <br>};</code>
|x3= <code>_fn_moveForward  <nowiki>=</nowiki> { /*...code...*/ };<br/>_fn_moveBackward <nowiki>=</nowiki> { /*...code...*/ };<br/>_fn_invalidKey  <nowiki>=</nowiki> { /*...code...*/ };<br/><br/>switch true do {<br/>&nbsp;&nbsp;[[case]] (_dikCode in actionKeys "MoveForward")  : _fn_moveForward;<br/>&nbsp;&nbsp;[[case]] (_dikCode in actionKeys "MoveBackward") : _fn_moveBackward;<br/>&nbsp;&nbsp;[[default]]                                        _fn_invalidKey;<br/>};<br/></code>
|x3= <code>_fn_moveForward  <nowiki>=</nowiki> { /*...code...*/ };<br/>_fn_moveBackward <nowiki>=</nowiki> { /*...code...*/ };<br/>_fn_invalidKey  <nowiki>=</nowiki> { /*...code...*/ };<br/><br/>switch true do {<br/>&nbsp;&nbsp;[[case]] (_dikCode in actionKeys "MoveForward")  : _fn_moveForward;<br/>&nbsp;&nbsp;[[case]] (_dikCode in actionKeys "MoveBackward") : _fn_moveBackward;<br/>&nbsp;&nbsp;[[default]]                                        _fn_invalidKey;<br/>};<br/></code>
|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>
<br>
<code>_var = "0"; //-> ["3", "0"]
_var = "1"; //-> ["2", "1"]
_var = "2"; //-> ["2", "2"]
_var = "3"; //-> ["3", "3"]
_var = "4"; //-> ["2", "4"]
_var = "5"; //-> ["default", "5"]</code>


| [[Control Structures]]  |= See also
| [[Control Structures]]  |= See also

Revision as of 18:32, 24 March 2014

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

Description

Description:
See switch do
Groups:
Uncategorised

Syntax

Syntax:
switch exp
Parameters:
exp: Anything
Return Value:
Switch Type

Examples

Example 1:
switch (_a) do {case 1 : {block}; case 2 : {block}; default {block};}
Example 2:
_color =
switch (side player) do
{
  case west: {"ColorGreen"};
  case east: {"ColorRed"};
};
Example 3:
_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;
};
Example 4:
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]}; };
_var = "0"; //-> ["3", "0"] _var = "1"; //-> ["2", "1"] _var = "2"; //-> ["2", "2"] _var = "3"; //-> ["3", "3"] _var = "4"; //-> ["2", "4"] _var = "5"; //-> ["default", "5"]

Additional Information

See also:
Control Structures

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