The problem is with the braces near the while() statement. It should look like this:

Code:

while(true) { motor(motorB) = -35; }

Tue Oct 19, 2010 7:41 pm

jbflot

Site Admin

Joined: Tue May 15, 2007 9:02 amPosts: 406

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.

while(SensorValue[sonic] > distance_in_cm) // While the Sonar Sensor readings are less than the specified, 'distance_in_cm': { motor[motorB] = 75; // Motor B is run at a 75 power level motor[motorC] = 75; // Motor C is run at a 75 power level } motor[motorB] = 0; // Motor B is stopped at a 0 power level motor[motorC] = 0; // Motor C is stopped at a 0 power level}

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 pmPosts: 124

Re: Why doesnt this code work?

boxr007 wrote:

Oh, and it compiles either way the brackets are near the while statement. Thanks anyway though

Code:

{ while(true) motor(motorB) = -35; }

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...

Who is online

Users browsing this forum: No registered users and 2 guests

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