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


Groupe Public active 1 week et 5 days ago

The user group for Antescofo.

Question about switch

Auteur 2 Utilisateurs souscrits |
Profile photo of 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]
Juillet 16, 2017 à 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.

  • Cette réponse a été modifiée 1 year et 3 months ago par Jean-Louis Giavitto Jean-Louis Giavitto. Raison: adding a remark
Juillet 17, 2017 à 18:00 #23076
Profile photo of 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.

Juillet 20, 2017 à 08:51 #23144

Vous devez être connecté pour répondre à ce sujet.

Log in now