IDK how to fix my code

#1

Vex keeps giving me this error Error:Executable statements not valid in ‘main’ declaration block after this code and its only on the last bracket

#pragma config(Motor, port2, rightmotor, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port3, leftmotor, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port6, armmotor, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port7, armmotor2, tmotorVex393_MC29, openLoop)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//

task main()
{
while(1 == 1)
{
motor[leftmotor] = vexRT[Ch3] / 2;
motor[rightmotor] = vexRT[Ch2] / 2;
if(vexRT[Btn6U] == 1)
{
motor[armmotor] = 40;
}
else if(vexRT[Btn6D] == 1)
{
motor[armmotor] = -40;
}
else
{
motor[armmotor] = 0;
}
}
}
if(vexRT[Btn5U] == 1)
{
motor[armmotor2] = 40;
}
else if(vexRT[Btn5D] == 1)
{
motor[armmotor2] = -40;
}
else
{
motor[armmotor2] = 0;
}

0 Likes

#2

I think you intended to do this, a part of the code was outside the main() task and the while loop:

#pragma config(Motor, port2, rightmotor, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port3, leftmotor, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port6, armmotor, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port7, armmotor2, tmotorVex393_MC29, openLoop)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//

task main()
{
	while(1 == 1)
	{
		motor[leftmotor] = vexRT[Ch3] / 2;
		motor[rightmotor] = vexRT[Ch2] / 2;
		if(vexRT[Btn6U] == 1)
		{
			motor[armmotor] = 40;
		}
		else if(vexRT[Btn6D] == 1)
		{
			motor[armmotor] = -40;
		}
		else
		{
			motor[armmotor] = 0;
		}
		
		if(vexRT[Btn5U] == 1)
		{
			motor[armmotor2] = 40;
		}
		else if(vexRT[Btn5D] == 1)
		{
			motor[armmotor2] = -40;
		}
		else
		{
			motor[armmotor2] = 0;
		}
	}
}

Original Code was:

#pragma config(Motor, port2, rightmotor, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port3, leftmotor, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port6, armmotor, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port7, armmotor2, tmotorVex393_MC29, openLoop)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//

task main()
{
	while(1 == 1)
	{
		motor[leftmotor] = vexRT[Ch3] / 2;
		motor[rightmotor] = vexRT[Ch2] / 2;
		if(vexRT[Btn6U] == 1)
		{
			motor[armmotor] = 40;
		}
		else if(vexRT[Btn6D] == 1)
		{
			motor[armmotor] = -40;
		}
		else
		{
			motor[armmotor] = 0;
		}
	}
}

	if(vexRT[Btn5U] == 1)
	{
		motor[armmotor2] = 40;
	}
	else if(vexRT[Btn5D] == 1)
	{
		motor[armmotor2] = -40;
	}
	else
	{
		motor[armmotor2] = 0;
	}
1 Like

#3

It can’t be stressed enough when starting with C-like syntax languages: pay attention to your formatting. We can’t see what the original formatting was since you didn’t use the code format on the forum (highlight code, press </> button), but if you make sure to start an extra indent after every { and remove one indent before every }, it would have been visually clear that your second if...else if...else block was outside of main. Which is a no-no.

2 Likes