View unanswered posts | View active topics It is currently Sat Sep 26, 2020 7:29 am

Reply to topic  [ 3 posts ] 
Type documentation 
Author Message

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

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:

word sonarValue = SensorValue(sonar);

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

correctly displays the sensor value, however

float sonarValue = SensorValue(sonar);

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

does not...


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

Joined: Wed Jan 24, 2007 10:44 am
Posts: 442
Location: Pittsburgh, PA
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":

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? Email ROBOTC Support at to put in a support ticket| Robomatter Store | Robotics Academy | CS2N

Fri Oct 26, 2007 10:46 am

Joined: Fri Feb 09, 2007 9:21 am
Posts: 616
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
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.