Asked — Edited
Resolved Resolved by Rich!

I Need Help

So I am coding some multi color recognition software in ez-script, but whenever I run the code it says that I am missing a binary operator in the command used to search for a color. pleass note that am running this code on a pc and not on the ez-b code is below ControlCommand("Camera", CameraMultiColorTrackingEnable) If($CameraObjectColor()= "color" ) Print("TWO") Elseif($CameraObjectColor()="color") Print("ONE") EndIf


ARC Pro

Upgrade to ARC Pro

Harnessing the power of ARC Pro, your robot can be more than just a simple automated machine.

United Kingdom
#1  

Remove the brackets from after the variable $CameraObjectColor

Also, you seem to be asking (in the script) the same thing for the IF and the ElseIF, however that wont throw an error since the IF will take priority and it will PRINT("TWO")

Hopefully that solves it however if it doesn't please post your project's .ezb file and I'll take a look at it (just one script isn't always enough since you will have other variables set up such as the custom colours.

#2  

Thanks, the code works now, and I can now pass coding class finals!;):D :)

#3  

Your code works fine in ARC... When you check syntax, anyway ...

#4  

So, along the same vane... (at the risk of being a thread jacker and possibly a dumb ass), how does one set up user variables in ARC? Or even can you? Or do you even have to? ARC is definitely not like any programing software I have ever used in the past....

United Kingdom
#5  

$variable = "whatever you want it to be"

$x = 1 $y = 7 $z = GetADC(ADC0) $a = GetRandom(0,100) $calc1 = $y * $a $text = "This is some text"

That's just a few ways :)

Basically, all variables begin with the $ character and then are a group of characters without spaces.

$xyz = will set the variable to whatever is after the =. That could be a number, a string (in quotes), a command such as GetADC, GetRandom, GetPWM etc. a calculation such as 1 * 2 + 3 or a calculation with variables like $voltage / $current. You can also use $x++ to increase $x by 1 (I presume it only works for decimal numbers though).

If you want a specific example give me the scenario and I'll explain it. Without a scenario it's difficult to cover every single method of creating variables. A good example to look at for use of variables and setting them are my Ping Roam scripts and my Battery Monitor script. Battery Monitor does some simple calculations too.

#6  

So you don't have to declare variables a head of time? You just start using them in the script, then?

Thanks Rich

#7  

Just define variables at the top of your script. Ideally an intit script.


$MyServo01 = "D0"
$MyPosition01 = 75
$MyPosition02 = 25
loop
Servo ($MyServo1, $MyPosition01)

Servo ($MyServo1, $MyPosition02)


This will in theory move the servo on D0 back and forth between 75 and 25.

Hope that helps

[edit]

Rich and I must have been typing at the same time. LOL

Once you define a variable it exists until the session ends. You can then call it and change it from any other script or control.

United Kingdom
#8  

Correct, no need to declare variables ahead of time. Just make sure if you have a command which uses a variable that it has been set before hand otherwise it will say it doesn't know what $variablename is.

For instance, run this code and it will throw an error;

IF($var1 > $var2)
  Print("Variable 1 is bigger")
ElseIF($var1 = $var2)
  Print("Variables are equal")
Else
  Print("Variable 2 is bigger")
EndIF

However, if you run this code it will work

$var1 = GetRandom(0,100)
$var2 = GetADC(ADC0)
IF($var1 > $var2)
  Print("Variable 1 is bigger")
ElseIF($var1 = $var2)
  Print("Variables are equal")
Else
  Print("Variable 2 is bigger")
EndIF

If the variable exists in another script or control ($soundservo, $CameraObjectColor etc) make sure the other script or control has run before you run the script or it will throw an error.

#9  

@Antron007 @Rich Awesome, thanks...;) Now just wish I had an EZB board to start fiddlin' with... :D

United Kingdom
#10  

You don't need an EZ-B to write scripts;) Although it does make it that much more awesome to see something move from a script but you can still sort out the backbone of the script(s) without an EZ-B.

This one for example doesn't even control anything yet (and is a little bit of a hint at what one of my future build's main function will be).

#11  

I'll check it out Rich... Cheers

Edit... Ok, LOL.... I can see how ARC can keep one busy indefinitely...

R ;)

#12  

Looks like you're making a Robo-Bartender. Very keen ;)