Home AMX User Forum NetLinx Studio

Select Active / Switch Case

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

Comments

  • Each ACTIVE statement could be looking different variables, so each one could be true. Each one that is will execute. On a SWITCH/CASE, you are only looking at one variable. Only one (or none) of the case's can be true at the same time.

    Kevin D.
  • ryanwwryanww Posts: 196
    Cool, thats what I thought.. Just wanted to make sure..

    Thanks
  • AM93AM93 Posts: 10
    No. In Amxland there is no fall-thru only the first true condition is executed the rest are ignored.

    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
  • ryanwwryanww Posts: 196
    Aw.. that sucks.. Well that would be a cool command for the future of AMX.. It would come in handy for me a few times.. Just a few less things to do..
  • I stand corrected. Never had a need for the first example but always assumed based on the wording. I almost ran a test program because I wasn't 100%.. Damn.

    Kevin D.
  • Man, it's right there in the help file too..
    The SELECT?ACTIVE statement provides a programming structure for selective execution of code blocks based on the evaluation of a series of conditions. The first block whose ACTIVE condition evaluates to true is executed; the remaining blocks are ignored. If no ACTIVE condition evaluates to true, no statements are executed.

    Kevin D
  • ericmedleyericmedley Posts: 4,177
    X=1, Y=1, Z=0
    IF(X)
    {DO SOMETHING}
    IF(Y)
    {DO SOMETHING ELSE}
    IF(Z)
    {DO SOMETHING ELSE}
    
    
    

    This will allow more than one state to fire in the same statement
  • mpullinmpullin Posts: 949
    switch...case

    It should also be noted switch...case in Netlinx has a subtle difference compared to every other language that structure appears.
    switch(nVar){
       case 1: SEND_COMMAND dvDev, 'A'; break;
       case 2:
       case 3:
       case 4:
       case 5: SEND_COMMAND dvDev, 'B'; break;
       case 6: SEND_COMMAND dvDev, 'C';
       default: SEND_COMMAND dvDev, 'D'; break;
    }
    
    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.
  • ryanwwryanww Posts: 196
    Well I am looking to do the opposite of that.. well kind of.. I just want one Select Active set but if say like multiple variables are true, it will fire those, but not necessarily together..
  • mpullin wrote:
    ... nVar=2, 3, 4, or 5 will all trigger B....

    Alternatively if you want nVar=2 to do nothing you need to add curly brackets to the code:

    case 2: {}
Sign In or Register to comment.