Asked
— Edited
using the goto command, it takes you to the specified command. does it keep playing the following commands so you can cause a loop or do you do that another way?
using the goto command, it takes you to the specified command. does it keep playing the following commands so you can cause a loop or do you do that another way?
subsequent instructions that would be below the goto command would not be executed.
Goto moves your location to the :Label
To return back from a goto() call, you use return
Example Goto Script;
This code will loop around 10 times, display "Hello World" 10 times then go to the end, print "Goodbye" and stop.
An example goto Script with a return (aka V1 of my IR detector script);
Now the script itself is written a bit back to front, the detect routine could have been placed above avoid and the initial goto removed. However this is a great example of how the goto, labels and return work.
The script (after the config part) will Goto the detect routine, it will check the ADC value of the IR sensor fitted to the EZB ADC port and if it meets the criteria it will Goto the avoid routine otherwise it will Goto the start of the detect routine.
The avoid routine runs it's commands to reverse and turn, then it Returns to where it came from, in this case, the detect routine.
Note the formatting of the explanation. Bold are the commands and italic are the labels.
Great information rich.
Thanks, Dave
It's a pleasure. It's also why I comment my scripts and I am going to claim that writing the above script backwards was all part of my plan to show Gotos and Returns (although it wasn't, I still have no clue why I wrote it that way round).
The script I used above also shows off If, ElseIf and Else, it's a great script to show someone as an example of some of the most used commands in EZ-Script. If only I had a reason to write more scripts... nothing is as relaxing as writing a script and little is as satisfying as writing a script which works