|
|
Line 72: |
Line 72: |
|
| |
|
| }} | | }} |
|
| |
| <h3 style="display:none">Notes</h3>
| |
| <dl class="command_description">
| |
| <!-- Note Section BEGIN -->
| |
|
| |
| <dd class="notedate">Posted on 07 Aug, 2008
| |
| <dt class="note">'''[[User:ColonelSandersLite|ColonelSandersLite]]'''<dd class="note"><br>
| |
| Be careful of the parenthesis around the variable you're switching on. If you accidentally use braces instead (ex: switch {_myVar} do{...), it won't error, but will always return default.<br>
| |
|
| |
|
| |
| <dd class="notedate">Posted on 11 Aug, 2008
| |
| <dt class="note">'''[[User:Dr_Eyeball|Dr_Eyeball]]'''<dd class="note">
| |
| Using [[switch]] with strings is case-sensitive, (unlike string comparisons).
| |
|
| |
|
| |
| <dd class="notedate">Posted on 12 Aug, 2008
| |
| <dt class="note">'''[[User:General_Barron|General Barron]]'''<dd class="note">
| |
| To be safe about the case sensitivity issue, use the [[toLower]] or [[toUpper]] command to force all strings to a certain case.
| |
|
| |
|
| |
| <dd class="notedate">Posted on 06 Oct, 2009
| |
| <dt class="note">'''[[User:Iva|Iva]]'''<dd class="note">
| |
| It's possible to use [[Boolean]] value as a switch and [[Code]] as case. One thing to take special care in such case is that code must be in parentheses. Example:
| |
| <code>
| |
| [[switch]] ([[true]]) [[do]]
| |
| {
| |
| [[case]] (_boolVar): {someCode};
| |
| [[case]] (unit1 [[distance]] unit2 > 5): {someCode};
| |
| };
| |
| </code>
| |
|
| |
|
| |
| <!-- Note Section END -->
| |
| </dl>
| |
|
| |
| [[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]
| |
| [[Category:Scripting Commands ArmA|{{uc:{{PAGENAME}}}}]]
| |
| [[Category:ArmA: Control Structures|{{uc:{{PAGENAME}}}}]]
| |
| [[Category:Command Group: Program Flow|{{uc:{{PAGENAME}}}}]]
| |
|
| |
| <!-- CONTINUE Notes -->
| |
| <dl class="command_description">
| |
| <dd class="notedate">Posted on November 6, 2014 - 16:33 (UTC)</dd>
| |
| <dt class="note">[[User:Eggbeast|Eggbeast]]</dt>
| |
| <dd class="note">
| |
| BEWARE:
| |
| <br>Sometimes, and I'm unsure why, numbers are treated differently (A2OA 1.63) with quote-wraps that worked
| |
| <br>in earlier code now not working unless quote-wraps are removed, with otherwise identical code.
| |
| <br><code>
| |
| _number1 = (floor random 10)
| |
| switch (_number1) do
| |
| {
| |
| case "0":
| |
| {
| |
| _vehicle setobjecttexture[0,"\mymodpath\textures\num1.paa"];
| |
| };
| |
| //etc
| |
| };
| |
| </code>
| |
| <br>
| |
| <br>this one below works, and the one above stopped working with 1.63
| |
| <br>
| |
| <code>
| |
| switch (_number1) do
| |
| {
| |
| case 0:
| |
| {
| |
| _vehicle setobjecttexture[0,"\mymodpath\textures\num1.paa"];
| |
| };
| |
| //etc
| |
| };
| |
| </code>
| |
| </dd>
| |
| </dl>
| |
| <!-- DISCONTINUE Notes -->
| |
|
| |
| <!-- CONTINUE Notes -->
| |
| <dl class="command_description">
| |
| <dd class="notedate">Posted on December 13, 2014 - 22:41 (UTC)</dd>
| |
| <dt class="note">[[User:Commy2|Commy2]]</dt>
| |
| <dd class="note">
| |
|
| |
| As of Arma 3 v1.36, switch returns true (BOOL) if the condition doesn't match any case and no default block is defined.<br>
| |
| <br>
| |
| switch (0) do {case (1): {"one"};}<br>
| |
| -> true
| |
|
| |
| </dd>
| |
| </dl>
| |
| <!-- DISCONTINUE Notes -->
| |
|
| |
| <!-- CONTINUE Notes -->
| |
| <dl class="command_description">
| |
| <dd class="notedate">Posted on December 14, 2014 - 04:18 (UTC)</dd>
| |
| <dt class="note">[[User:DreadedEntity|DreadedEntity]]</dt>
| |
| <dd class="note">
| |
| Function names can be used in place of code, as shown in Example 3.
| |
| </dd>
| |
| </dl>
| |
| <!-- DISCONTINUE Notes -->
| |