Magicode is absolutely correct, the issue is that you are using untilTouch(bump) as a condition for the if statement. When we break the two pieces of code down, we see that:

The 'If' statement check to see 'if' the condition(s) inside of its parentheses is true (or, a logic '1' value). If the condition evaluates to true (does 1 == 1? Yes, so that would be a true statement and return a value of 1. Does 2 == 1? No, so the condition is false and returns a 0) the code inside of the if statement's curly braces will execute. In this case, it is the stopMotor(motor1); command. If the condition is false, the program flow picks up at the end of the if statement (the closing brace).

The untilTouch(bump) statement is a bit different. It halts the program flow 'until' the 'bump' sensor is 'touch'ed. When the bump sensor is touched, the program flow will continue past the untilTouch(bump) statement. The untilTouch command monitors a sensor (in this case, the sensor named 'bump') and does not return a value when the sensor gives the value of 1.

So the problem is that the code is actually executing something like this: 'Does nothing?'. Since the untilTouch command does not return a value, the if statement has nothing to compare it to and therefore does not work.

To check a sensor value in an if statement, you will have to use the SensorValue[] command. This tells ROBOTC to check the value of the specified sensor (in this case, 'bump') for a value.

Code:

if (SensorValue[bump] == 1) { stopMotor(motor1); }

This will check the value returned by the touch sensor named 'bump' and, if it is a 1, will stop motor1. Note that while touch sensors are switches and will only return a 0 or a 1 depending on their state, other sensors can return a wider range of values (depending on the sensor). You can still use the if statement to check their values, though, but may need to change the '1' to a more appropriate value.

I suggest taking a look at our Natural Language resources that covers all of the Natural Language commands. Also, check out our Natural Language (for Cortex) section on our wiki, which is a superb reference tool: http://www.robotc.net/wiki/VEX2_Natural_Language

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