How to work with variables in SPIN
TechnoSam
Posts: 2
Hey everyone,
I'm brand new to the Propellor chip, and I'm having a really hard time with it. I want to do a calcuation with variables. Basically, I'm writing a method that converts a number of inches to travel into seconds that the robot has to move forward. I found that 1 second equals 6.5 inches. I want to call my "Forward" method on a single parameter (distance).
I tried:
distance = distance/6.5
and I got the error: "Variable needs operator."
I went back and initialized a new variable, but I still got the same message. I have NO IDEA how to do anything with variables in this language and the Help files don't even touch on it. All I want to do is set some variable equal to my parameter divided by 6.5.
Can someone PLEASE help me out? Thanks.
I'm brand new to the Propellor chip, and I'm having a really hard time with it. I want to do a calcuation with variables. Basically, I'm writing a method that converts a number of inches to travel into seconds that the robot has to move forward. I found that 1 second equals 6.5 inches. I want to call my "Forward" method on a single parameter (distance).
I tried:
distance = distance/6.5
and I got the error: "Variable needs operator."
I went back and initialized a new variable, but I still got the same message. I have NO IDEA how to do anything with variables in this language and the Help files don't even touch on it. All I want to do is set some variable equal to my parameter divided by 6.5.
Can someone PLEASE help me out? Thanks.
Comments
1. The assignment operator in Spin is := (colon-equals), not = (equals).
2. Spin does not do floating -point math natively. However, to divide by 6.5, just multiply by 2 first, then divide by 13.
3. Welcome to the Parallax forum!
-Phil
So basically only integers are allowed?
Thanks a lot!