02-11-2010 07:30 AM
Hello, I need some help with while loops and sequences. I have 3sequences, and each includes at least one while loop. And I'd like to stop each while loop with the same button. besides this, If I pushed this bttton, I'd like to start in sequence 0 again. maybe it would work with events - what do you think?
Thanx for ya help
02-11-2010 07:47 AM - edited 02-11-2010 07:48 AM
You can use local variables to stop any separate loops you want with a single button. Right-click on a button and select Create -> Local variable. Then deploy it in the desirable loop and wire its output to the conditional terminal of the loop.
Edit: Just don't overuse the locals while programming.
02-11-2010 07:47 AM
02-11-2010 07:59 AM
The advice you have received will get you out of the while loops, but the remainder of the sequence(s) will execute to completion before anything else can happen. To restart a sequence you would need to enclose it in another while loop.
What your description implies is that it will be very difficult for you to get the program to work the way you want it to with the methods you are using. A much better way would be to switch to a state machine architecture. The minimum implementation is a while loop enclosing a case structure. Each case represents a state. The case selector is wired to a shift register to pass the next state selection from one iteration to the next. There are many examples which come with LV and lots of posts on the Forums about state machines.
Lynn
02-11-2010 08:05 AM