|
Page 1 of 1
|
[ 7 posts ] |
|
Why doesnt this code work?
Author |
Message |
boxr007
Rookie
Joined: Fri Oct 15, 2010 2:20 pm Posts: 17 Location: Rochdale, UK
|
 Why doesnt this code work?
Ok, so im just about starting to write some test programs, just to get more confident with the NXT system, and this one program, doesnt compile....why?? It has an error next to the if statement. thanks guys.
|
Tue Oct 19, 2010 6:54 pm |
|
 |
Gary Samad
Expert
Joined: Mon Mar 15, 2010 4:24 pm Posts: 124
|
 Re: Why doesnt this code work?
The problem is with the braces near the while() statement. It should look like this:
|
Tue Oct 19, 2010 7:41 pm |
|
 |
jbflot
Site Admin
Joined: Tue May 15, 2007 9:02 am Posts: 409
|
 Re: Why doesnt this code work?
The reason it doesn't compile is the condition in the if statement "SensorValue(sensorSONAR)>distance_in_cm". "sensorSonar" is a sensor type in ROBOTC, that allows you to specify which port a sonar sensor is connected. It's not an instance of a sonar sensor that you can use in a conditional comparison. Sensors in ROBOTC must first be configured using the Motors and Sensors Setup menu. Check out this sample code that uses the sonar sensor:
|
Tue Oct 19, 2010 9:48 pm |
|
 |
boxr007
Rookie
Joined: Fri Oct 15, 2010 2:20 pm Posts: 17 Location: Rochdale, UK
|
 Re: Why doesnt this code work?
Oh yeah, I have just assigned the sensors, and it works!!  Thanks loads.
|
Wed Oct 20, 2010 4:56 pm |
|
 |
boxr007
Rookie
Joined: Fri Oct 15, 2010 2:20 pm Posts: 17 Location: Rochdale, UK
|
 Re: Why doesnt this code work?
Oh, and it compiles either way the brackets are near the while statement. Thanks anyway though 
|
Wed Oct 20, 2010 4:59 pm |
|
 |
Gary Samad
Expert
Joined: Mon Mar 15, 2010 4:24 pm Posts: 124
|
 Re: Why doesnt this code work?
Well, ok, I guess I see that it could compile, but that is some bizarre syntax. Also, it looks to me like it would simply run an infinite loop setting the motor speed to -35 forever. It would never get past this to the "if" statement... cu, Gary
|
Wed Oct 20, 2010 5:55 pm |
|
 |
boxr007
Rookie
Joined: Fri Oct 15, 2010 2:20 pm Posts: 17 Location: Rochdale, UK
|
 Re: Why doesnt this code work?
I know...unfortunately, my programming skills are somewhat, shall we say, basic  lol. I am learning tho! lol.
|
Sat Oct 23, 2010 7:00 am |
|
|
|
Page 1 of 1
|
[ 7 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 0 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
|
|