Group Admins

  • Profile picture of echeveste
  • Profile picture of Jean-Louis Giavitto
  • Profile picture of Philippe Cuvillier
  • Profile picture of arshiacont

Antescofo

Public Group active 1 day, 23 hours ago

The user group for Antescofo.

Question about switch

Author 2 Subscribed Users |
Profile photo of maladie
maladie

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]
          }
July 16, 2017 at 22:25 #23052
Jean-Louis Giavitto
Jean-Louis Giavitto

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.

July 17, 2017 at 18:00 #23076
Profile photo of maladie
maladie

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

July 20, 2017 at 08:51 #23144

You must be logged in to reply to this topic.

Log in now