Asked — Edited

Unsure About Errors

Here are the errors:

13: Print( "Battery is "$voltageAA )
> Error on line 13: Missing binary operator: 
"Battery is " [?] 67

15: Filewriteline( "C:\Users\dylan_000\Desktop\AAlog.txt", $number + 1 ":" $voltageAA)
> Error on line 15: Missing binary operator: 
1 [?] ":"
":" [?] 69
Done (00:00:03.7516495)

Here's the script:

$voltageAA = 0
print( "Load battery" )

#Claw closed
servo(d0, 95)
servo(d1, 121)

#check and log voltage
$voltageAA = getadc(7)
Print( "Battery is "$voltageAA )
Filewriteline( "C:\Users\dylan_000\Desktop\AAlog.txt", $number + 1 ":" $voltageAA)

#claw open
servo(d0, 50)
servo(d1, 150)

#door open
servo(d2, 95)

#door closed
servo(d2, 175)


What do I have to do to fix them? I'm sure its just my script.


Upgrade to ARC Pro

Stay at the forefront of robot programming innovation with ARC Pro, ensuring your robot is always equipped with the latest advancements.


Because you're not appending the variable to the string...

This is wrong:

Print( "Battery is "$voltageAA )

This is correct:

Print( "Battery is "  + $voltageAA )

Without it, you would have to begin understanding binary operations - which you don't, hence the question about the error :)


But what about the second one. It outputs

$number + 1 : $voltageAA

to the file. How do I fix that?

It should output

2: 127

or similar.


It's the same problem. You left out the + operators again:

Filewriteline( "C:\Users\dylan_000\Desktop\AAlog.txt", $number+1 ":" $voltageAA)
           # Should be:
Filewriteline( "C:\Users\dylan_000\Desktop\AAlog.txt", $number+1 + ": " + $voltageAA)

There has to be a plus sign between each and every separate thing you are trying to combine into one sentence. In this case the + operator is being used in two different ways depending on context. The first one ($number+1), is used as a math addition operator. In the other cases it is being used as an append operator (as DJ mentioned above).


Alright, so spaces vs no spaces. Got it. Will test it tomorrow.


Umm, no. It's not about the spaces. It's about the adding of the plus signs:

Filewriteline( "C:\Users\dylan_000\Desktop\AAlog.txt", $number+1 + ": " + $voltageAA)
#                                                                |      |
#                                                     Added Plus sign operators

I added a space with the colon so as to separate the colon from the $voltageAA value in the output, but that has nothing to do with why it didn't work. For instance:

Filewriteline( "C:\Users\dylan_000\Desktop\AAlog.txt", $number + 1 + ": " + $voltageAA)

      #  Will work the same as:

Filewriteline( "C:\Users\dylan_000\Desktop\AAlog.txt", $number+1+": "+$voltageAA)

The spaces between the parts make no difference.