Looping and Subroutines
Previous Top Next

Two advanced GP3EZ techniques are looping and subroutines.

Consider a script that looks like this:
  
ID
Tag
Condition
Action
Next
1
Start
Always
Set Loop A 5
 
2
blinkloop
Always
 
Goto blinker (bookmark)
3
 
Always
 
Goto blinkloop (Loop A)
4
 
After 5000ms
 
Goto Start
5
blinker
After 250ms
LED off
 
6
 
After 250ms
LED on
Last Bookmark


Step 1 sets loop counter A (there are three loop counters: A, B, and C) to 5.

Step 2 jumps to the blinker "subroutine" (in other words, a chunk of steps we want to use more than once from different parts of the script). Note that it sets the bookmark so blinker can come back here. In this simple example, blinker is only used once, but a complex script might use the same subroutine in many places.

After step 2, the next step that runs is step 5 which just delays and turns the LED on. Step 6 also delays. Then it turns off the LED and jumps back to the last set bookmark which means the next step will be step 3.

Step 3 doesn't do anything except jump to the blinkloop step (step 2). However, it does so with the Loop A box checked. that means GP3EZ will decrease the loop counter by 1 and only jump to blinkloop if A is greater than 0. So the first time through, A will be set to 4 (remember it was set to 5 in step 1) and GP3EZ will continue at step 2. However, after 5 times, A will be set to 0 and the jump will not occur. In that case, the GP3EZ will continue at step 4.

Step 4 waits 5 seconds and starts the whole script over again by jumping to the Start tag.