Switch cases

Help
Dave
2013-03-15
2013-05-21
  • Dave
    Dave
    2013-03-15

    I recently downloaded this program and  have been testing a few programs that I have written, however the program doesn't like switch statements I get this error

    " Mistake while reading the program: switch(## isn't known! "

    First I thought it might be the program I had written however I then tested an earlier version of the program (a very basic sumo bot program with only line detection) that worked on the actual hardware in university and it gives me the same error.

    This is the basic program that's not working.

    int state = 0 ; // 0 = roam 1= right avoid 2= left avoid 
    task main()
    {
          SetSensorColorFull(IN_2);
          SetSensorColorFull(IN_3);
         while (true)
         {
             switch (state)
             {
         
                 case 0 :
                 OnRev(OUT_AC, 75);
         
                 if ( Sensor(IN_3)!= 1)
                     {
                         state = 2;
                     }
                            
                 if ( Sensor(IN_2)!= 1)
                     {
                         state = 1;
                     }
                 break;
                 
                 case 1:
                   
                   OnFwd (OUT_AC,75);              
                   Wait (400);
                   OnRev (OUT_C,75);
                   Wait (1000);
                   
                   state = 0;
                   break;
                   
                   case 2:
                   
                   OnFwd (OUT_AC,75);              
                   Wait (400);
                   OnRev (OUT_A,75);
                   Wait (1000);
                   
                   state = 0;
                   break;
               }
               
         }
    }
    

    Im using nxceditor 0.1.1

    Any help is much appreciated.

    Thanks
    Dave

     
  • Dave
    Dave
    2013-03-15

    Just as a side note the program compiles fine its only the emulator that doesn't like it.

     
  • Knefel
    Knefel
    2013-03-15

    Hello Dave,

    I wrote the nxcSimulator for my students. Since this is a program for beginners, not all NXC commands are included. There is a list of all commands that one can use inside the nxcSimulator (nxcSimulator: "Help" -> "show commands for the simulator" - "switch … case" is not included). I will add further orders to the nxcSimulator, if I need them in the classroom (or if I have boredom).

    knefel

     
  • Knefel
    Knefel
    2013-03-15

    By the way:
    The nxcSimulator checks whether or not he knows certain commands when the program starts. "Mistake while reading the program: switch (# # is not known" is the output of the nxcSimulator.

     
  • Dave
    Dave
    2013-03-15

    Thanks for getting back to me so quickly.

    Its a shame to hear that because this is one of the best linux nxc programs I have found.

    Hope your class enjoy using it and that you keep on developing it, it would be amazing to one day see a full emulator.

    Thanks again
    Dave

     
  • Knefel
    Knefel
    2013-05-21

    ... now "switch ... case" is added to the simulator and some other commands (for-loop, one-dimensional array works without ArrayInit, function calls ... return, NumOut and TextOut with coordinate values ​​(multiples of 6 and 8), ... ).
    If you are missing something in the simulator or editor: In the forum "Open Discussion" there is a "wish list".