< Back to IRCAM Forum

Question about switch

Hi, I have been using Antescofo for a little while now and absolutely love the language. However, recently I realized some bizarre behaviour with the switch function. I’ve used it before without any problems whatsoever but for some reason the following code does not work at all. The exact same code with several ifs works perfectly. With the switch function, none of the cases are ever entered. Even by adding a case where > 0 which should include everything does not work. Any ideas of what could be the problem?

Thank you for the help

        switch ($note_rand) {  
          case $note_rand >= 0 && $note_rand <= $note1:  
            $note := $possible_notes[0]  
          case $note_rand > $note1 && $note_rand <= ($note1 + $note2):  
            $note := $possible_notes[1]  
          case $note_rand > ($note1 + $note2) && $note_rand <= ($note1 + $note2 + $note3):  
            $note := $possible_notes[2]  
          case $note_rand > ($note1 + $note2 + $note3) && $note_rand <= ($note1 + $note2 + $note3 + $note4):  
            $note := $possible_notes[3]  
          }

Hello Maladie.

There are two forms for the switch statement.

The first one Alternative Actions without Selectors does not use a selector and the argument of case is a boolean expression.

The second form Alternative Action with a Selector takes a selector and the argument of case is an arbitrary expression which is compared with (or applied to) the value of the selector.

Your code fragment seems to mix the two forms. Try to suppress the ($note_rand) after the switch.

The same remark apply for statment switch and for extended expression switch.

Aw, thank you very much Jean-Louis. I had a creeping suspicion that it could be related to that but I was still unsure.