Int main bracket errors

Hello again. I have been having some problems with the int main part of the program having errors. It works sometimes, and other times not. It occasionally just says that the int main() is not allowed, and that it is missing a curly brace when it is not. Here is the program typed in the competition template.

void preAutonomous(void) {
  // actions to do when the program starts
  Brain.Screen.clearScreen();
  Brain.Screen.print("pre auton code");
  wait(1, seconds);
}

void autonomous(void) {
  Brain.Screen.clearScreen();
  Brain.Screen.print("autonomous code");
   vex::motor_group Conveyor(LConv, RConv);
  vex::motor_group Arm (LArm, RArm);
  Arm.setVelocity(75,percent);
  Conveyor.setVelocity(67,percent);
  
  if (true){
  Brain.Screen.clearScreen();
  Drivetrain.driveFor(forward, 457, mm);
  Drivetrain.turnFor(right, 90, degrees);
  Arm.spinFor(forward, 400, degrees);
  Drivetrain.driveFor(forward, 350, mm);
  Conveyor.spinFor(reverse, 720, degrees);
  Drivetrain.driveFor(reverse, 300, mm);
  Arm.spinFor(reverse, 400, degrees);
  Drivetrain.turnFor(left, 120,degrees);
  }
}
 
void userControl(void) {
  Brain.Screen.clearScreen();
 vex::motor_group Arm (LArm, RArm);
 vex::motor_group Conveyor (LConv, RConv);
  while (true) {
    if (Controller1.ButtonL1.pressing()){
        Conveyor.spin(forward);
    }
    else if (Controller1.ButtonL2.pressing()){
        Conveyor.spin(reverse);
    }
    else{
        Conveyor.stop();
        Conveyor.setStopping(hold);
    }
    if (Controller1.ButtonR1.pressing()){
        Arm.spin(forward);
    }
    else if (Controller1.ButtonR2.pressing()){
        Arm.spin(reverse);
    }
    else{
        Arm.stop();
        Arm.setStopping(hold);
    }
}
    

int main() {
  // create competition instance
  competition Competition;
  // Set up callbacks for autonomous and driver control periods.
  Competition.autonomous(autonomous);
  Competition.drivercontrol(userControl);
  // Run the pre-autonomous function.
  preAutonomous();
  // Prevent main from exiting with an infinite loop.
  while (true) {
    wait(100, msec);
  }
}

edit by mods, add code tags

you are missing the closing brace for the while loop in userControl

6 Likes

Oh. Silly me. Thanks though!

1 Like

One more question is how would I spin the conveyor and drive forward at the same time?

Drivetrain.driveFor(forward, 350, mm, false);
  Conveyor.spinFor(reverse, 720, degrees); 

If you add the false at the end, it is effectively just saying "run this line and do not wait for it to be done until it runs the next task’. This will make it spin the drivetrain and the conveyor

2 Likes

Thanks for the help!

1 Like