Asked — Edited
Resolved Resolved by Dunning-Kruger!

Can Someone Tell Me Whats Wrong With Script

Can someone look at this script and tell me what is missing? Ive tried several elseif, endif, combinations and can not make work? Thanks

:MonitorDistances $leftsensor = getadc(adc5) $topsensor = getadc(adc7) $rightsensor = getadc(adc6)

if ($leftsensor 60) ControlCommand("Script Manager ", ScriptStop, "forward_3_Seconds") ElseIf goto(MonitorDistances)


ARC Pro

Upgrade to ARC Pro

ARC Pro is more than a tool; it's a creative playground for robot enthusiasts, where you can turn your wildest ideas into reality.

#1  

:MonitorDistances $leftsensor = getadc(adc5) $topsensor = getadc(adc7) $rightsensor = getadc(adc6)

if ($leftsensor <60)And ($rightsensor <60) ControlCommand("Script Manager ", ScriptStop, "forward_3_Seconds") ElseIf if ($leftsensor >60) ControlCommand("Script Manager ", ScriptStop, "forward_3_Seconds") ElseIf goto(MonitorDistances)

#2  

You need an "endif" and a sleep(100) or so to slow down the loop a bit and a comparison on this line if ($leftsensor 60)

However in your script if either of the conditions are met the controlcommad executes the same forward_3_seconds Cheat Sheet command


:MonitorDistances
$leftsensor = getadc(adc5)
$topsensor = getadc(adc7)
$rightsensor = getadc(adc6)


if ($leftsensor &lt;60)And ($rightsensor &lt;60)
 ControlCommand(&quot;Script Manager &quot;, ScriptStop, &quot;forward_3_Seconds&quot;)
 ElseIf ($leftsensor &gt;60)
ControlCommand(&quot;Script Manager &quot;, ScriptStop, &quot;forward_3_Seconds&quot;)
endif
sleep(100)
goto(MonitorDistances)

#3  

I have no idea why my first script posted like that. I assume you looked at the second one? Thanks

#4  

Hey Chris


:MonitorDistances
$leftsensor = getadc(adc5)
$topsensor = getadc(adc7)
$rightsensor = getadc(adc6)


if ($leftsensor &lt;60)And ($rightsensor &lt;60)
ControlCommand(&quot;Script Manager &quot;, ScriptStop, &quot;forward_3_Seconds&quot;)
EndIf
if ($leftsensor &gt;60)
ControlCommand(&quot;Script Manager &quot;, ScriptStop, &quot;forward_3_Seconds&quot;)
endif  
sleep(100)
goto(MonitorDistances)

or


:MonitorDistances
$leftsensor = getadc(adc5)
$topsensor = getadc(adc7)
$rightsensor = getadc(adc6)


if ($leftsensor &lt;60)And ($rightsensor &lt;60)
ControlCommand(&quot;Script Manager &quot;, ScriptStop, &quot;forward_3_Seconds&quot;)
ELSEIF ($leftsensor &gt;60)
ControlCommand(&quot;Script Manager &quot;, ScriptStop, &quot;forward_3_Seconds&quot;)
endif  
sleep(100)
goto(MonitorDistances)

#5  

I did... have a look... I am not sure it is what you want but it should run without error...

#6  

@kamaroman68 You can give the credit to David if you like...I am not looking to get any more credits right now... By the way, there wasn't really anything wrong with your script... just need a bit of tweaking.... You had the logic down so that was good...:)

#7  

You both deserve the credit. Your speedy response warrants the credit! I appreciate the help immensely! Thanks

With that.............

I am missing a very easy and fundamental part of programming with ez script...

I actually program allen Bradley, Schneider electric, and direct logic PLCs for a living in a factory environment. When there is a line of code that is not correct it will tell me exactly which line or lines are at fault. My error when doing "check syntax" kept giving me an error of missing end statements or something like that. I wasn't sure how to determine which line was causing the error. Is there such a function in ez script? I see the little orange lines in the script editor to the left of each line but what do those mean? Thanks again!

#8  

There is nothing that will take you to the error like in other languages. You will be directed that there there is a missing closing statement (endif/endrepeat/endrepeatuntil/repeatwhile/endrepeatwhile/etc)

This is one of the main reasons that I like to make each script do one thing and only one thing as yours is doing. its when they get long and are doing many things that finding the missing (endif/endrepeat/endrepeatuntil/repeatwhile/endrepeatwhile/etc) becomes difficult.

Every if statement must have an endif even if there is an elseif between them


IF(condition)
       dosomething here
ELSEIF(another condition)
       dosomething else here
ELSEIF(another condition)
      dosomething else here
EndIF

you can nest if statements like this


if(condition)
if(another condition)
#do something here that meets both conditions
elseif(condition3)
#do something here if only the first condition is met
endif
else
#do something here if the first condition isnt met
endif

#9  

one other piece of advice.


if(x-1=2)
#dosomething
endif
#dosomething

if you put this into the script, notice that there is a + sign next to the if statement. there is a line down to the end if there is a little line going right to the end if.

This lets you know which endif is going with which if. This will let you see that this is a complete block. if the line just keeps going, it isnt a complete block of code.

This will let you know that the endif is where you expect it to be.