not defined at global scope level

I’m learning functions and get the error task main not defined at global scope level.

#pragma config(Sensor, in6, potentiometer, sensorPotentiometer)
#pragma config(Sensor, dgtl1, rightEncoder, sensorQuadEncoder)
#pragma config(Sensor, dgtl3, leftEncoder, sensorQuadEncoder)
#pragma config(Sensor, dgtl6, frontTouch, sensorTouch)
#pragma config(Sensor, dgtl8, sonarCM, sensorSONAR_cm)
#pragma config(Motor, port2, rightMotor, tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor, port3, leftMotor, tmotorServoContinuousRotation, openLoop)
#pragma config(Motor, port6, armMotor, tmotorServoContinuousRotation, openLoop)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//

/----------------------------------------------------------------------------------------------------
|* - Forward for Distance with Encoders - |
|
ROBOTC on VEX 2.0 CORTEX |
|
|
|
This program instructs the robot to move forward for 5 rotations of the left shaft encoder. |
|
|
|
ROBOT CONFIGURATION |
|
NOTES: |
|
1) Reversing ‘rightMotor’ (port 2) in the “Motors and Sensors Setup” is needed with the |
|
“Squarebot” model, but may not be needed for all robot configurations. |
|
2) Whichever encoder is being used for feedback should be cleared just before it starts |
|
counting by using the “SensorValue(encoder) = 0;”. This helps ensure consistancy. |
|
|
|
MOTORS & SENSORS: |
|
* [Name] [Type] [Description] |
|
Motor - Port 2 rightMotor VEX 3-wire module Right side motor |
|
Motor - Port 3 leftMotor VEX 3-wire module Left side motor |
|
Digital - Port 1,2 rightEncoder VEX Shaft Encoder Right side |
|
Digital - Port 3,4 leftEncoder VEX Shaft Encoder Left side |
*----------------------------------------------------------------------------------------------------
/

//+++++++++++++++++++++++++++++++++++++++++++++| MAIN |+++++++++++++++++++++++++++++++++++++++++++++++

void moveStraight ()

{
SensorValue[rightEncoder] = 0;
SensorValue[leftEncoder] = 0;
//First Forward Movement
while(SensorValue[leftEncoder] < 550) // While less than 550 for forward to 2’
{

//...Move Forward

if(SensorValue[leftEncoder]> SensorValue[rightEncoder])
{
motor[rightMotor] = 127;
motor[leftMotor] = 127;
}
if(SensorValue[rightEncoder]> SensorValue[leftEncoder])
{
motor[rightMotor] = 127;
motor[leftMotor] = 127;
}
if(SensorValue[leftEncoder]== SensorValue[rightEncoder])
{
motor[rightMotor] = 127;
motor[leftMotor] = 127;
}
}
task main()
{

wait1Msec(500); // .5 Second Delay

//Clear Encoders
SensorValue[rightEncoder] = 0;
SensorValue[leftEncoder] = 0;

while(SensorValue[leftEncoder] < 550) // While less than 550 for forward to 2’
{

//...Move Forward
	if(SensorValue[leftEncoder]> SensorValue[rightEncoder])
{
	motor[rightMotor] = 127;
	motor[leftMotor] = 127;

}
if(SensorValue[rightEncoder]> SensorValue[leftEncoder])
{
motor[rightMotor] = 127;
motor[leftMotor] = 127;
}
if(SensorValue[leftEncoder]== SensorValue[rightEncoder])
{
motor[rightMotor] = 127;
motor[leftMotor] = 127;
}
wait1Msec(500); // .5 Second Delay
}
SensorValue[rightEncoder] = 0;
SensorValue[leftEncoder] = 0;

while(SensorValue[leftEncoder] > -550) // While greater than -550 for reverse to 2’

if(SensorValue[leftEncoder]> SensorValue[rightEncoder])
{
motor[rightMotor] = -127;
motor[leftMotor] = -127;
}
if(SensorValue[rightEncoder]> SensorValue[leftEncoder])
{
motor[rightMotor] = -127;
motor[leftMotor] = -127;
}
if(SensorValue[leftEncoder]== SensorValue[rightEncoder])
{
motor[rightMotor] = -127;
motor[leftMotor] = -127;
}
wait1Msec(500); // .5 Second Delay
SensorValue[rightEncoder] = 0;
SensorValue[leftEncoder] = 0;

while(SensorValue[leftEncoder] < 1350) // While less than 1800 for forward to 4’

if(SensorValue[leftEncoder]> SensorValue[rightEncoder])
{
motor[rightMotor] = 127;
motor[leftMotor] = 127;
}
if(SensorValue[rightEncoder]> SensorValue[leftEncoder])
{
motor[rightMotor] = 127;
motor[leftMotor] = 127;
}
if(SensorValue[leftEncoder]== SensorValue[rightEncoder])
{
motor[rightMotor] = 127;
motor[leftMotor] = 127;
}
wait1Msec(1000); // .5 Second Delay
SensorValue[rightEncoder] = 0;
SensorValue[leftEncoder] = 0;

while(SensorValue[leftEncoder] > -1650) // While less than 1800 for reverse to start

if(SensorValue[leftEncoder]> SensorValue[rightEncoder])
{
motor[rightMotor] = -127;
motor[leftMotor] = -127;
}
if(SensorValue[rightEncoder]> SensorValue[leftEncoder])
{
motor[rightMotor] = -127;
motor[leftMotor] = -127;
}
if(SensorValue[leftEncoder]== SensorValue[rightEncoder])
{
motor[rightMotor] = -127;
motor[leftMotor] = -127;
}

while(SensorValue[leftEncoder] < 1900) // While less than 1900 for forward to 6’

if(SensorValue[leftEncoder]> SensorValue[rightEncoder])
{
motor[rightMotor] = 127;
motor[leftMotor] = 127;
}
if(SensorValue[rightEncoder]> SensorValue[leftEncoder])
{
motor[rightMotor] = 127;
motor[leftMotor] = 127;
}
if(SensorValue[leftEncoder]== SensorValue[rightEncoder])
{
motor[rightMotor] = 127;
motor[leftMotor] = 127;
}
wait1Msec(1000); // .5 Second Delay

while(SensorValue[leftEncoder] > -1900) // While less than 1800 for reverse to start

if(SensorValue[leftEncoder]> SensorValue[rightEncoder])
{
motor[rightMotor] = -127;
motor[leftMotor] = -127;
}
if(SensorValue[rightEncoder]> SensorValue[leftEncoder])
{
motor[rightMotor] = -127;
motor[leftMotor] = -127;
}
if(SensorValue[leftEncoder]== SensorValue[rightEncoder])
{
motor[rightMotor] = -127;
motor[leftMotor] = -127;
}
}
}*

The reason you are seeing this is because there is a closing brace } missing from the moveStraight() function. You can use the format whole file tool (found under the Edit -> Code Formatting -> Format Whole File menu, or as the ‘magic wand’ tool in the Edit toolbar at the top ROBOTC) to line up the braces and help give a visual on which brace is missing.

In the future, make sure to post your code using the

[CODE]
tags, as it is much easier for us to debug the program that way.

Thank you :slight_smile:

Another question: I’m learning functions, in the attached program the difference in my encoder count in the move straight function between 2012 and 2013 is dramatic. That’s got me stumped.
functions #1.c (4.78 KB)