Situation: I've looked over all the scripts in the cloud and haven't seemed to find anything pertaining to looping. So I wanted to write a short tutorial for the community. So the simple loop example went okay, but as I wrote a loop within a loop. I am finding myself a little confused as the the process flow of the following code...
Here is the script:
#Loop With In Loop
Print("Loop with a loop")
$OuterCounter = 3
$InnerCounter = 2
:OuterLoopStep
If ($OuterCounter >= 0)
#Execute Outer Loop Command
Print(">Outer Loop Value: $OuterCounter)
$OuterCounter = $OuterCounter - 1
:InnerLoopStep
If ($InnerCounter >= 0)
#Execute Inner Loop Command
Print("Inner Loop Value: $InnerCounter")
$InnerCounter = $InnerCounter - 1
Goto (InnerLoopStep)
Else
Sleep(3000)
Goto(OuterLoopStep)
#Wanted to use EndIf for formality, but not nessecary
Else
Print("Finished")
EndIf
Here is the output of the debugger: Start 2: Print("Loop with a loop") Loop with a loop 3: $OuterCounter = 3 4: $InnerCounter = 2 6: :OuterLoopStep 7: If ($OuterCounter >= 0) 9: Print(">Outer Loop Value: $OuterCounter)
Outer Loop Value: 3 10: $OuterCounter = $OuterCounter - 1 12: :InnerLoopStep 13: If ($InnerCounter >= 0) 15: Print("Inner Loop Value: $InnerCounter") Inner Loop Value: 2 16: $InnerCounter = $InnerCounter - 1 17: Goto (InnerLoopStep) 13: If ($InnerCounter >= 0) 15: Print("Inner Loop Value: $InnerCounter") Inner Loop Value: 1 16: $InnerCounter = $InnerCounter - 1 17: Goto (InnerLoopStep) 13: If ($InnerCounter >= 0) 15: Print("Inner Loop Value: $InnerCounter") Inner Loop Value: 0 16: $InnerCounter = $InnerCounter - 1 17: Goto (InnerLoopStep) 13: If ($InnerCounter >= 0) 18: Else 19: Sleep(3000) 20: Goto(OuterLoopStep) 7: If ($OuterCounter >= 0) 9: Print(">Outer Loop Value: $OuterCounter) Outer Loop Value: 2 10: $OuterCounter = $OuterCounter - 1 12: :InnerLoopStep 13: If ($InnerCounter >= 0) 18: Else 19: Sleep(3000) 20: Goto(OuterLoopStep) 7: If ($OuterCounter >= 0) 9: Print(">Outer Loop Value: $OuterCounter) Outer Loop Value: 1 10: $OuterCounter = $OuterCounter - 1 12: :InnerLoopStep 13: If ($InnerCounter >= 0) 18: Else 19: Sleep(3000) 20: Goto(OuterLoopStep) 7: If ($OuterCounter >= 0) 9: Print(">Outer Loop Value: $OuterCounter) >Outer Loop Value: 0 10: $OuterCounter = $OuterCounter - 1 12: :InnerLoopStep 13: If ($InnerCounter >= 0) 18: Else 19: Sleep(3000) 20: Goto(OuterLoopStep) Here's where my confusion starts. Any ideas? Am I missing something obvious? 7: If ($OuterCounter >= 0) 10: $OuterCounter = $OuterCounter - 1 12: :InnerLoopStep 13: If ($InnerCounter >= 0) 18: Else 19: Sleep(3000) 20: Goto(OuterLoopStep) 7: If ($OuterCounter >= 0) 10: $OuterCounter = $OuterCounter - 1 12: :InnerLoopStep 13: If ($InnerCounter >= 0) 18: Else 19: Sleep(3000) 20: Goto(OuterLoopStep) 7: If ($OuterCounter >= 0) 10: $OuterCounter = $OuterCounter - 1 12: :InnerLoopStep 13: If ($InnerCounter >= 0) 18: Else 19: Sleep(3000) 20: Goto(OuterLoopStep)
and on and on the loop executes...
@DJ Sures
I thought I smelled smoke on the nested if, but just hadn't done the testing to make the case to you... Man your quick.
@LeversofPower
Thanks dude. It's a great test. When I did the If/ElseIf/Else/Endif a few weeks ago, I thought of that logic condition - but I didn't review it enough. I love how close we are as a community
The progress EZ-Robot has made in a year gives me the hugest smile. Love it!
Can't wait to see your android app working too. That's such a good idea.
This next release of ARC that i'm working on today has significant improvements for the http url parser, windows 8 tcp server bug fix, and a few other goodies like this...
This kind of works for you right now, $x = 2 > 1 This doesn't work but will work in next release, $x = 2 = 2
And a few fixes like this thread topic logic bug
.. sometimes I should sleep when i'm tired, instead of programming haha
WOW DJ is like 146,252 operations per second in his brain!
and thanks to leversofpower for "if ing" the envelope!
Interesting insight into EZ-Script, I know
, but it seems that name has stuck. I was really hoping when looking at the product I wouldn't have to get into typing hundreds of curly braces and semicolons to soon.
Thanks for the tip on the debug checkbox. At a cursory glance I didn't pick up on just the operations.
Of course when you feel like it, or on the todo list, or whatever the flow is: Is a pause button in the config window next to the run button is asking to much, otherwise I got a feeling I'm going to be doing a lot of sleeping.
Oh, and a scroll bar on the script control output window...
Interesting request for a pause button. You'd like to manually start, stop and pause the script?
Can you give me a rundown on the program you'd like to see this functionality for?
You guys make my head hurt. This thread really shows me how far out of this stuff I really am.
Thanks God for the "EZ" part.
@leversofpower, Yeah, formatting. Never having taken a single day of programming in my life, I usually just trip and fall my way through this stuff.
Took me three sessions to get this "code" (not script, hehe) working. And since I'm on the bleeding edge of understanding it all, debugging takes on a whole new sense of shock and awe
@DJ, Pause (Global, in the case of running from the script control interface) would be nice. I just found myself in a nasty endless-loop-of-doom(tm) whereby no matter how much I pounded on the stop button on the main script, it just ran away because I'm nesting my script command calls.
Had to literally pull the plug and shut down the app to get back to "normal".
Wall-E started compacting the cat and drinking all the GOOD scotch!
Hmmm, aside from it being useful when testing loops. Not sure I have a specific program in mind at this time. I would say a pause button would not be even be a medium priority enhancement but just nice to have. It seems only useful on scripts of over hundred lines and that run a series of steps rapidly that display a lot in the debug window.
I've only been messing with ARC a couple of days. So it went like this: Camera control, sweet. HTTP server even better. Then, since I'm a programmer by hobby and trade, I immediately went to the script window and started typing. And that's where I've been and where I'll be until the RoboQuad remote is hacked or until the hardware from China arrives in my mail box.
@dschulpius We must all start from somewhere. I was planning a looping tutorial to help out the community. If you have any scripting questions or ideas let me know. I do not know anything about electronics let alone integrating with EZ-B, but my starting point is some cheap stepper motors from china:
Stepper
and this comes next on my plan: Shift Register
used with this Robot Eye
To make this replacement head for RoboQuad:
Big plans I know, we'll see I guess...