Announcement

Collapse
No announcement yet.

Continuous loop, updated by serin()

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Continuous loop, updated by serin()

    I have two blocks of code that need to loop continuously to simulate stripes moving left or right across the screen. I want to use the serin() function to change which of the two blocks is currently looping. Please help me figure out what's wrong with the code below. The first serin() command is read but the code is only executed once and no further commands are effective.
    Many thanks.

    func main()var char;var whichloop;
    repeat while(((char := serin()) < 0) || whichloop > 0);

    switch case(char == 'A') whichloop := 'A';
    case(char == 'B') whichloop := 'B';
    endswitch

    switch case(whichloop == 'A')
    [loop A];
    case(whichloop == 'B')
    [loop B]; endswitch

    foreverendfunc

  • #2


    How do the 'loops' break out, it would appear, from what is shown that the code will only work 'once'?

    What you need to do is set up a small comms buffer and break out of the loop when com_Count() is not 0
    Mark

    Comment


    • #3


      Okay, I think I have it working. To create the buffer I used this code from another thread:

      var combuf[24]; com_Init(combuf, 48, 0); setbaud(BAUD_115200);

      I have no idea what the first two lines mean. Is there any documentation for creating a buffer?

      Comment


      • #4


        Um it's documented under com_Init in the Goldelox 4DGL internal functions reference.

        You can find that under 'Designer Environment Documentation' here http://www.4dsystems.com.au/product/10/120/Development/4D_Workshop_4_IDE/
        Mark

        Comment


        • #5


          Thank you

          Comment

          Working...
          X