switch do: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (VBS2 scripting category removal)
(mass edit: removing obsolete </dt> and </dd> tags)
Line 46: Line 46:
<!-- Note Section BEGIN -->
<!-- Note Section BEGIN -->


<dd class="notedate">Posted on 07 Aug, 2008</dd>
<dd class="notedate">Posted on 07 Aug, 2008
<dt class="note">'''[[User:ColonelSandersLite|ColonelSandersLite]]'''</dt><dd class="note"><br>
<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>
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>


<dd class="notedate">Posted on 11 Aug, 2008</dd>
 
<dt class="note">'''[[User:Dr_Eyeball|Dr_Eyeball]]'''</dt><dd class="note">
<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).
Using [[switch]] with strings is case-sensitive, (unlike string comparisons).
</dd>


<dd class="notedate">Posted on 12 Aug, 2008</dd>
 
<dt class="note">'''[[User:General_Barron|General Barron]]'''</dt><dd class="note">
<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.
To be safe about the case sensitivity issue, use the [[toLower]] or [[toUpper]] command to force all strings to a certain case.
</dd>


<dd class="notedate">Posted on 06 Oct, 2009</dd>
 
<dt class="note">'''[[User:Iva|Iva]]'''</dt><dd class="note">
<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:
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>
<code>
Line 71: Line 71:
};
};
</code>
</code>
</dd>
 


<!-- Note Section END -->
<!-- Note Section END -->

Revision as of 02:56, 18 October 2011

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

Description

Description:
Switch form.
Groups:
Uncategorised

Syntax

Syntax:
switch do block
Parameters:
switch: Switch Type
block: Code
Return Value:
Anything

Examples

Example 1:
switch (_condition) do { case 1: {hint "1"}; case 2: {hint "2"}; default {hint "default"}; };
Example 2:
switch (_condition) do { case true: {hint "true"}; case false: {hint "false"}; default {hint "default"}; };
Example 3:
switch (_condition) do { case "string1": {hint "string1"}; case "string2": {hint "string2"}; default {hint "default"}; };

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

Posted on 07 Aug, 2008
ColonelSandersLite

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.
Posted on 11 Aug, 2008
Dr_Eyeball
Using switch with strings is case-sensitive, (unlike string comparisons).
Posted on 12 Aug, 2008
General Barron
To be safe about the case sensitivity issue, use the toLower or toUpper command to force all strings to a certain case.
Posted on 06 Oct, 2009
Iva
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: switch (true) do { case (_boolVar): {someCode}; case (unit1 distance unit2 > 5): {someCode}; };