Select Active / Switch Case
ryanww
Posts: 196
So in either Select Active or Switch Case, can multiple instances happen? I would guess more so with Select Active..
Here is an example:
X=1, Y=1, Z=0
SELECT
{
ACTIVE (X):
{DO SOMETHING}
ACTIVE (Y):
{DO SOMETHING ELSE}
ACTIVE (Z):
{DO SOMETHING ELSE}
}
Would both the commands in X and Y execute assuming both statments were true?
Thanks
Here is an example:
X=1, Y=1, Z=0
SELECT
{
ACTIVE (X):
{DO SOMETHING}
ACTIVE (Y):
{DO SOMETHING ELSE}
ACTIVE (Z):
{DO SOMETHING ELSE}
}
Would both the commands in X and Y execute assuming both statments were true?
Thanks
0
Comments
Kevin D.
Thanks
So for easy examples you could do:
Select
{
Active ((X) || (Y) || (Z)): Do Stuff if you want the same result
}
OR
If (X) Do thing #1
If (Y) Do thing #2
If (Z) Do thing #3
Kevin D.
Kevin D
This will allow more than one state to fire in the same statement
It should also be noted switch...case in Netlinx has a subtle difference compared to every other language that structure appears. nVar=1 only triggers A. nVar=2, 3, 4, or 5 will all trigger B. However, you would expect (if you came from other languages) that nVar=6 would trigger C and D, but no, it only triggers C.
The case only falls through in the case of a totally empty case. The break keyword in a switch...case is merely cosmetic in this langauge.
Alternatively if you want nVar=2 to do nothing you need to add curly brackets to the code:
case 2: {}