Plz check my code

#include “robot-config.h”
/---------------------------------------------------------------------------/
/* /
/
Description: Competition template for VCS VEX V5 /
/
/
/
---------------------------------------------------------------------------*/

//Creates a competition object that allows access to Competition methods.
vex::competition Competition;

/---------------------------------------------------------------------------/
/* Pre-Autonomous Functions /
/
/
/
You may want to perform some actions before the competition starts. /
/
Do them in the following function. You must return from this function /
/
or the autonomous and usercontrol tasks will not be started. This /
/
function is only called once after the cortex has been powered on and /
/
not every time that the robot is disabled. /
/
---------------------------------------------------------------------------*/

void pre_auton( void ) {
// All activities that occur before the competition starts
// Example: clearing encoders, setting servo positions, …

}

/---------------------------------------------------------------------------/
/* /
/
Autonomous Task /
/
/
/
This task is used to control your robot during the autonomous phase of /
/
a VEX Competition. /
/
/
/
You must modify the code to add your own robot specific commands here. /
/
---------------------------------------------------------------------------*/

void autonomous( void ) {
while(Sonar1.distance(distanceUnits::in) <8)
{
Arm1.spin(vex::directionType::fwd,200, vex::velocityUnits::pct);

}
while(Sonar1.distance(distanceUnits::in)>8)
{
Frontleftmotor.spin(vex::directionType::fwd,200,vex::velocityUnits::pct);
Backleftmotor.spin(vex::directionType::fwd,200, vex::velocityUnits::pct);

Backrightmotor.spin(vex::directionType::fwd,200, vex::velocityUnits::pct);
Frontrightmotor.spin(vex::directionType::fwd,200, vex::velocityUnits::pct);
}
Frontleftmotor.stop();
Frontrightmotor.stop();
Backleftmotor.stop();
Backrightmotor.stop();

/----------------------------------------------------------------------------/
/* /
/
User Control Task /
/
/
/
This task is used to control your robot during the user control phase of /
/
a VEX Competition. /
/
/
/
You must modify the code to add your own robot specific commands here. /
/
----------------------------------------------------------------------------*/

void usercontrol( void );{
Backleftmotor.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct); //(Axis3+Axis4)/2
Backrightmotor.spin(vex::directionType::fwd, Controller1.Axis2.value(), vex::velocityUnits::pct);//(Axis1-Axis2)/2
Frontleftmotor.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct); //(Axis2+Axis1)/2
Frontrightmotor.spin(vex::directionType::fwd, Controller1.Axis2.value(), vex::velocityUnits::pct); //(Axis4+Axis3)/2

if (Controller1.ButtonUp.pressing())
{

Arm1.spin(vex::directionType::fwd,200, vex::velocityUnits::pct);

}

else if (Controller1.ButtonDown.pressing())
{

Arm1.spin(vex::directionType::rev, 200, vex::velocityUnits::pct);

}

else if (!Controller1.ButtonUp.pressing())
{

Arm1.stop();

}

       else if (!Controller1.ButtonDown.pressing())
       {
           Arm1.stop();
       }

while (1){

vex::task::sleep(20); //Sleep the task for a short amount of time to prevent wasted resources. 

}
}

//
// Main will set up the competition functions and callbacks.
//
int main();
//Run the pre-autonomous function.
pre_auton();

//Set up callbacks for autonomous and driver control periods.
Competition.autonomous( autonomous );
Competition.drivercontrol( usercontrol );

//Prevent main from exiting with an infinite loop.                        
while(1) {using namespace vex;



while(true)




  vex::task::sleep(100);//Sleep the task for a short amount of time to prevent wasted resources.
}    

}

Just try this. I give up at trying to verbally explain what needs to be changed.

#include "robot-config.h"
/*---------------------------------------------------------------------------*/
/* */
/* Description: Competition template for VCS VEX V5 */
/* */
/*---------------------------------------------------------------------------*/
using namespace vex;
//Creates a competition object that allows access to Competition methods.
vex::competition Competition;


/*---------------------------------------------------------------------------*/
/* Pre-Autonomous Functions */
/* */
/* You may want to perform some actions before the competition starts. */
/* Do them in the following function. You must return from this function */
/* or the autonomous and usercontrol tasks will not be started. This */
/* function is only called once after the cortex has been powered on and */
/* not every time that the robot is disabled. */
/*---------------------------------------------------------------------------*/

void pre_auton( void ) {
// All activities that occur before the competition starts
// Example: clearing encoders, setting servo positions, ...

}

/*---------------------------------------------------------------------------*/
/* */
/* Autonomous Task */
/* */
/* This task is used to control your robot during the autonomous phase of */
/* a VEX Competition. */
/* */
/* You must modify the code to add your own robot specific commands here. */
/*---------------------------------------------------------------------------*/

void autonomous( void ) {
while(Sonar1.distance(distanceUnits::in) <8) 
{
Arm1.spin(vex::directionType::fwd,200, vex::velocityUnits::pct);


}
while(Sonar1.distance(distanceUnits::in)>8)
{
Frontleftmotor.spin(vex::directionType::fwd,200,vex::velocityUnits::pct);
Backleftmotor.spin(vex::directionType::fwd,200, vex::velocityUnits::pct);

Backrightmotor.spin(vex::directionType::fwd,200, vex::velocityUnits::pct);
Frontrightmotor.spin(vex::directionType::fwd,200, vex::velocityUnits::pct);
}
Frontleftmotor.stop();
Frontrightmotor.stop(); 
Backleftmotor.stop();
Backrightmotor.stop();
}
/*----------------------------------------------------------------------------*/
/* */
/* User Control Task */
/* */
/* This task is used to control your robot during the user control phase of */
/* a VEX Competition. */
/* */
/* You must modify the code to add your own robot specific commands here. */
/*----------------------------------------------------------------------------*/

void usercontrol( void ){
Backleftmotor.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct); //(Axis3+Axis4)/2
Backrightmotor.spin(vex::directionType::fwd, Controller1.Axis2.value(), vex::velocityUnits::pct);//(Axis1-Axis2)/2
Frontleftmotor.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct); //(Axis2+Axis1)/2
Frontrightmotor.spin(vex::directionType::fwd, Controller1.Axis2.value(), vex::velocityUnits::pct); //(Axis4+Axis3)/2

if (Controller1.ButtonUp.pressing())
{

Arm1.spin(vex::directionType::fwd,200, vex::velocityUnits::pct);

}

else if (Controller1.ButtonDown.pressing())
{

Arm1.spin(vex::directionType::rev, 200, vex::velocityUnits::pct);
} 


else if (!Controller1.ButtonUp.pressing())
{

Arm1.stop();
} 


else if (!Controller1.ButtonDown.pressing())
{
Arm1.stop();
}


while (1){


vex::task::sleep(20); //Sleep the task for a short amount of time to prevent wasted resources. 
}
}

//
// Main will set up the competition functions and callbacks.
//
int main(){ 
//Run the pre-autonomous function. 
pre_auton();

//Set up callbacks for autonomous and driver control periods.
Competition.autonomous( autonomous );
Competition.drivercontrol( usercontrol );

//Prevent main from exiting with an infinite loop. 
while(1) {


while(true)

vex::task::sleep(100);//Sleep the task for a short amount of time to prevent wasted resources.
} 

}

Essentially, your problem had to deal with incorrect nesting of brackets. Every time you define a pre_auton, autonomous, and usercontrol, you end the line with only a { . You do not end with a ; or a ;{, just a {. In addition, make sure that every time you open a bracket, you close it before you enter the next portion that is done.

I outright cannot help you with troubleshooting on what you actually want to do. I can only help with making the code actually download to the robot. I don’t know why there is a while(true) inside a while loop, but at this point, if it works, it works.

Good luck with your competition tomorrow, and tell us how it goes!

Thankyou so much. I did not look at that strand. Thanks for your help. I’ll let you know how it goes.

Would this be correct because in the Competition temeplate it ended up like this. I put the code in the Void user control and then it gets weird . I saw the while 1 after the Competition.(Auton) and Competition.(Usercontrol)

#include “robot-config.h”
/---------------------------------------------------------------------------/
/* /
/
Description: Competition template for VCS VEX V5 /
/
/
/
---------------------------------------------------------------------------*/

//Creates a competition object that allows access to Competition methods.
vex::competition Competition;

/---------------------------------------------------------------------------/
/* Pre-Autonomous Functions /
/
/
/
You may want to perform some actions before the competition starts. /
/
Do them in the following function. You must return from this function /
/
or the autonomous and usercontrol tasks will not be started. This /
/
function is only called once after the cortex has been powered on and /
/
not every time that the robot is disabled. /
/
---------------------------------------------------------------------------*/

void pre_auton( void ) {
// All activities that occur before the competition starts
// Example: clearing encoders, setting servo positions, …

}

/---------------------------------------------------------------------------/
/* /
/
Autonomous Task /
/
/
/
This task is used to control your robot during the autonomous phase of /
/
a VEX Competition. /
/
/
/
You must modify the code to add your own robot specific commands here. /
/
---------------------------------------------------------------------------*/

void autonomous( void ) {

}

/----------------------------------------------------------------------------/
/* /
/
User Control Task /
/
/
/
This task is used to control your robot during the user control phase of /
/
a VEX Competition. /
/
/
/
You must modify the code to add your own robot specific commands here. /
/
----------------------------------------------------------------------------*/

void usercontrol( void ) {

while (1){
Backleftmotor.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct); //(Axis3+Axis4)/2
Backrightmotor.spin(vex::directionType::fwd, Controller1.Axis2.value(), vex::velocityUnits::pct);//(Axis1-Axis2)/2
Frontleftmotor.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct); //(Axis2+Axis1)/2
Frontrightmotor.spin(vex::directionType::fwd, Controller1.Axis2.value(), vex::velocityUnits::pct); //(Axis4+Axis3)/2

if (Controller1.ButtonUp.pressing())
{

Arm1.spin(vex::directionType::fwd,200, vex::velocityUnits::pct);

}

else if (Controller1.ButtonDown.pressing())
{

Arm1.spin(vex::directionType::rev, 200, vex::velocityUnits::pct);

}

else if (!Controller1.ButtonUp.pressing())
{

Arm1.stop();

}

       else if (!Controller1.ButtonDown.pressing())
       {
           Arm1.stop();
       }

vex::task::sleep(20); //Sleep the task for a short amount of time to prevent wasted resources. 

}
}

//
// Main will set up the competition functions and callbacks.
//
int main()

//Run the pre-autonomous function. 
pre_auton();

//Set up callbacks for autonomous and driver control periods.
Competition.autonomous( autonomous );
Competition.drivercontrol( usercontrol );

//Prevent main from exiting with an infinite loop.                        
while(1) {
  vex::task::sleep(100);//Sleep the task for a short amount of time to prevent wasted resources.
}    

}

Sorry wrong one

#include “robot-config.h”
/---------------------------------------------------------------------------/
/* /
/
Description: Competition template for VCS VEX V5 /
/
/
/
---------------------------------------------------------------------------*/

//Creates a competition object that allows access to Competition methods.
vex::competition Competition;

/---------------------------------------------------------------------------/
/* Pre-Autonomous Functions /
/
/
/
You may want to perform some actions before the competition starts. /
/
Do them in the following function. You must return from this function /
/
or the autonomous and usercontrol tasks will not be started. This /
/
function is only called once after the cortex has been powered on and /
/
not every time that the robot is disabled. /
/
---------------------------------------------------------------------------*/

void pre_auton( void ) {
// All activities that occur before the competition starts
// Example: clearing encoders, setting servo positions, …

}

/---------------------------------------------------------------------------/
/* /
/
Autonomous Task /
/
/
/
This task is used to control your robot during the autonomous phase of /
/
a VEX Competition. /
/
/
/
You must modify the code to add your own robot specific commands here. /
/
---------------------------------------------------------------------------*/

void autonomous( void ) {

}

/----------------------------------------------------------------------------/
/* /
/
User Control Task /
/
/
/
This task is used to control your robot during the user control phase of /
/
a VEX Competition. /
/
/
/
You must modify the code to add your own robot specific commands here. /
/
----------------------------------------------------------------------------*/

void usercontrol( void ) {

while (1){
Backleftmotor.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct); //(Axis3+Axis4)/2
Backrightmotor.spin(vex::directionType::fwd, Controller1.Axis2.value(), vex::velocityUnits::pct);//(Axis1-Axis2)/2
Frontleftmotor.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct); //(Axis2+Axis1)/2
Frontrightmotor.spin(vex::directionType::fwd, Controller1.Axis2.value(), vex::velocityUnits::pct); //(Axis4+Axis3)/2

if (Controller1.ButtonUp.pressing())
{

Arm1.spin(vex::directionType::fwd,200, vex::velocityUnits::pct);

}

else if (Controller1.ButtonDown.pressing())
{

Arm1.spin(vex::directionType::rev, 200, vex::velocityUnits::pct);

}

else if (!Controller1.ButtonUp.pressing())
{

Arm1.stop();

}

       else if (!Controller1.ButtonDown.pressing())
       {
           Arm1.stop();
       }

vex::task::sleep(20); //Sleep the task for a short amount of time to prevent wasted resources. 

}
}

//
// Main will set up the competition functions and callbacks.
//
int main()

//Run the pre-autonomous function. 
pre_auton();

//Set up callbacks for autonomous and driver control periods.
Competition.autonomous( autonomous );
Competition.drivercontrol( usercontrol );

//Prevent main from exiting with an infinite loop.                        
while(1) {
  vex::task::sleep(100);//Sleep the task for a short amount of time to prevent wasted resources.
}    

}

In line 117 of the code below it says that the function ( I believe is the Curly bracket) is not allowed there

Literally just open up a new document, and copy and paste what I posted the first time. Although it isn’t line for line what the template states, it shouldn’t matter.

I think you misunderstood me when I said every time you “define” something. You only “define” a function once, which was when you placed code within something like void autonomous( void ) { }. In the main task, what you are doing is only referencing the functions. Therefore, you only need to use a semicolon after the line, as evidenced in the lines


pre_auton();

,


Competition.autonomous( autonomous );

, and


Competition.drivercontrol( usercontrol );

Edit: From now on, if you are going to ask help with your code, can you just attach it using the “Attach a file”, like what I am doing to the .vex file? I say this because we really shouldn’t have lines of code just continuously copied and pasted.
Firerobot1008.vex (8.5 KB)

I understand but it keeps saying that the 2nd while statement before the sleep statement is an unqualified ID.

Ok i will do that from now on

It keeps saying that the 2nd while statement is an unqualified ID

OH, that’s my bad. If you click the title of your code, do you see this thing? If so, make sure the box is blue.
thingy.PNG

Ok i changed it to that

I changed it to that

Here is that line
I am not able to post it in the code format

while(1) {//this is where the error is
vex::task::sleep(20); //Sleep the task for a short amount of time to prevent wasted resources.
}

…I do get an error, which is resolved by deleting line 9, which states vex::competition Competition;. That happens because by having using namespace vex;, there is redundancy. Try that first, then tell me if it still won’t compile.

Yeah i got an error at line 9 too
One sec

The reasonfor why I just did not copy your code is because I wanted it to beMINE and i wanted to have the expeirence.

I am still getting an error message at the 2nd while statement

I deleted line 9

I am still getting an error message at the 2nd while statement

I deleted line 9

Yeah i got an error at line 9 too
One sec

The reasonfor why I just did not copy your code is because I wanted it to beMINE and i wanted to have the expeirence.