View unanswered posts | View active topics It is currently Fri Apr 18, 2014 5:08 pm






Reply to topic  [ 3 posts ] 
Type documentation 
Author Message
Rookie

Joined: Wed Mar 14, 2007 6:23 pm
Posts: 1
Post Type documentation
Hi,

Anyone know if there are any docs on variable types, e.g. float, int, word etc? I initially thought that C docs would be close enough, but it seems that's not the case.

I suppose this is a +1 for a manual! Or at least something on the wiki?

I was specifically looking for docs on 'word' as I'm not sure if a word should be getting truncated to 0 when assigned to a float.

For example:

Code:
word sonarValue = SensorValue(sonar);

nxtDisplayTextLine(1,  "%s = %4d", "Sonar", sonarValue);


correctly displays the sensor value, however

Code:
float sonarValue = SensorValue(sonar);

nxtDisplayTextLine(1,  "%s = %4d", "Sonar", sonarValue);


does not...

_________________
Nick


Thu Oct 25, 2007 5:16 pm
Profile
Site Admin
Site Admin

Joined: Wed Jan 24, 2007 10:44 am
Posts: 438
Location: Pittsburgh, PA
Post 
Hi Nick, normally when you would want to show float in a display line like that, you would have to replace the "d" with "f":

Code:
nxtDisplayTextLine(1,  "%s = %4f", "Sonar", sonarValue);


That should work for you. Although I believe the NXT does not support using floats for the sonar's value so it doesn't give you any decimal place values.

I have sent a message to our developer to see if he has any insight on this.

_________________
Vu Nguyen
Software Training Development Team | Webmaster
Need more support? Use the ROBOTC Ticketing system

Robotc.net| Robomatter Store | Robotics Academy | CS2N


Fri Oct 26, 2007 10:46 am
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 614
Post 
ROBOTC (and standard C) requires the user to properly match the format codes with the variable types in a print statement.

So if you use a "%d" code with a float variable you'll get unexpected results as the internal float variable representation will be interpreted as an integer in the print formating code.


Fri Oct 26, 2007 11:32 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.