[OCCRA]: Common 2016 OCCRA programming mistakes

Hi I’m Pete you may know me as an inspector or for some of you that guy that helped you with your code at the competition,
I’ve noticed a couple of common mistakes lots of teams are making when programming their robots this year. I’m gonna keep a running list here as the season goes on so if you are having issues with your code you may be able to find the answer here.

The first most common issue I’ve seen is people making is trying to set up their motors to buttons incorrectly the symptoms of this are the motor spins one way fine but the other way it moves slowly or jumps a bit.
The incorrect code looks like this:

if(vexRT[Btn5U] == 1)
{
	motor[leftMotor] = 127
}
if(vexRT[Btn5U] == 0)
{
	motor[leftMotor] = 0
}
if(vexRT[Btn5D] == 1)
{
	motor[leftMotor] = -127
}
if(vexRT[Btn5D] == 0)
{
	motor[leftMotor] = 0
}

Now to see why that will not work lets walk through it line by line in its failure case

if(vexRT[Btn5U] == 1)// or (1 == 1) or True, We are holding down the up button so its value is pressed or 1
{
	motor[leftMotor] = 127 //The motor is now set to 127 or full forward
}
//Motor is full forward or 127
if(vexRT[Btn5U] == 0)// or (1 == 0) or False, We are holding down the up button so its value is pressed or 1
{
	motor[leftMotor] = 0 //This set 0 does not run as expected since 1 is not equal to 0 go figure
}
//Motor is still full forward or 127 due to the last if failed again no issues so far
if(vexRT[Btn5D] == 1)// or (0 == 1) or False, We are NOT holding down the down button so its value is NOT pressed or 0
{
	motor[leftMotor] = -127 //This set -127 does not run as expected since 1 is not equal to 0 go figure
}
//The motor is still going full forward 127 which is again expected as we are only holding the up button
if(vexRT[Btn5D] == 0)// or (0 == 0) or True, This is the start of our problem this statement is also True lets keep going and see the effect this has 
{
	motor[leftMotor] = 0 //Now we are setting the motor to 0 or Stopped 
}
//Now even though we are holding the up button down the motor has been stopped due to the fact that the code for the down button not being pressed was put after the up button set the motor to full forward causing it to almost immediately turn the motor back off

One of the ways of fixing this is to use an else if statement as shown below


if (vexRT[Btn5U] == 1)
{
	motor[leftMotor] = 127
}
else if (vexRT[Btn5U] == 1)
{
	motor[leftMotor] = -127
}
else
{
	motor[leftMotor] = 0
}

In this case an else if will protect ageist that issue due to the fact it leaves no case where the code can contradict itself and set the value of the motor twice in one loop of the code.

More common issues to be posted shortly.