Lego color sensor

Using RobotC, on the Lego NXT 'bot, the Color Sensor (by Lego) will correctly identify colors using the View tab, ColorSensor tab, ie when not programmed in from RobotC. When I write a program that uses the color sensor to move when on specific color, the color sensor doesn’t seem to detect color.
task main {
if (SensorValue (colorSensor == yellow))
motor[motorA] = 50;
motor[motorC] = 50;
}
Or, if the 'bot is on a white surface going forward and to stop at a black line,

if (SensorValue (colorSensor != black))
motor[motorA] = 50;
motor[motorC] = 50;
The commands compile and download OK.

The color sensor doesn’t work any better when placed in another port. The color ssensors emitting LED doesn’t appear to “shine” during the program. I tried the short program from BotBench that uses a while loop and switch/case command to test color sensing and this program works correctly.
I went back and tried to declare each color as a variable - see below:
task main ()
{
string sColor1;
sColor1 = “BLACKCOLOR”;
string sColor2;
sColor2 = “BLUECOLOR”;
string sColor3;
sColor3 = “YELLOWCOLOR”;
string sColor4;
sColor4 = “???”

if (SensorValue (lightSensor == sColor4))
{
nSyncedMotors = synchAC;
nSyncedTurnRatio = 100;
motor [motorA] = 70;
}
else (SensorValue (lightSensor == sColor1));
{
motor[motorC] = -70;
motor{motorA] = -70;
wait1msec (500);

motor[motorC] = 70;
motor[motorA] = -70;
wait1Msec (1000);
}
}
when compiling - the error message is: 1. Invalid comparison with 'char and ‘string’ types. 2. internal compiler Mixed mode (string/byte) comparison in conditional branch.

Any help you can give me on getting started with the color sensor would be appreciated. Also, I can’t find any examples of code used in a program that uses the color sensor, out on the web, any suggestions?
Thanks in advance - Dave

Two pieces of advice:

  1. The “SensorValue()” command should only have the name of the sensor placed in between the parenthesis. In each of your if statements, you include the comparison between the parenthesis. For example, “if (SensorValue (colorSensor != black))” should be “if (SensorValue (colorSensor) != black)”

  2. Second, there are a few other mistakes, like including a condition after an “else” branch of the if statement. Else branches are meant for “all other cases when the preceeding “if” is false”, so they don’t get them. In ROBOTC if you go to File > Open Sample Program, you’ll find a folder named “LEGO Color Sensor” that should help get you started.

Now, all that said, while this is a ROBOTC forum, the VEX folks are kind enough to host it to help support their products, not the LEGO ones. For future LEGO questions, please post at http://robotc.net/forums/ and we’ll be more than happy to help you over there.