Shop OBEX P1 Docs P2 Docs Learn Events
How to work with variables in SPIN — Parallax Forums

How to work with variables in SPIN

TechnoSamTechnoSam Posts: 2
edited 2012-10-15 17:27 in Propeller 1
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.

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-10-15 16:09
    Three things:

    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
  • TechnoSamTechnoSam Posts: 2
    edited 2012-10-15 17:15
    Ah, I see. Thanks!

    So basically only integers are allowed?

    Thanks a lot! :smile:
  • JonnyMacJonnyMac Posts: 9,108
    edited 2012-10-15 17:27
    Natively, Spin supports signed-integers. By using an object (library) you can add floating point support.
Sign In or Register to comment.