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:


:start
$voltageAA = 0
print( "Load battery" )
Sleep(2000)

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

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

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

#door open
servo(d2, 95)
sleep(500)

#door closed
servo(d2, 175)

Goto(start)

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


ARC Pro

Upgrade to ARC Pro

Experience early access to the latest features and updates. You'll have everything that is needed to unleash your robot's potential.

PRO
Synthiam
#1  

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:)

#2  

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.

#3  

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).

#4  

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

#5  

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.