1

This is my first time working on c++ and I have no idea how to fix this, I've asked around for a while but got no answer. Deleting either of the int main() will cause an error, I also tried putting void and that didn't work.

error shown: Redefinition of 'main' (63, 5)

#include "vex.h"
  
// Allows for easier use of the VEX Library
using namespace vex;

float myVariable;

// "when Controller1 Axis3 changed" hat block
void onevent_Controller1Axis3Changed_0() {
  Motor1.setVelocity(Controller1.Axis3.position(), percent);
  Motor2.setVelocity(Controller1.Axis3.position(), percent);
  Motor1.spin(forward);
  Motor2.spin(forward);
}

// "when Controller1 Axis2 changed" hat block
void onevent_Controller1Axis2Changed_0() {
  Motor11.setVelocity(Controller1.Axis2.position(), percent);
  Motor12.setVelocity(Controller1.Axis2.position(), percent);
  Motor11.spin(forward);
  Motor12.spin(forward);
}


int main() {
  // register event handlers
  Controller1.Axis3.changed(onevent_Controller1Axis3Changed_0);
  Controller1.Axis2.changed(onevent_Controller1Axis2Changed_0);

  wait(15, msec);
  // post event registration

  // set default print color to black
  printf("\033[30m");

  // wait for rotation sensor to fully initialize
  wait(30, msec);

}
// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name]               [Type]        [Port(s)]
// Controller1          controller                    
// Motor1               motor         1               
// Motor2               motor         2               
// Motor11              motor         11              
// Motor12              motor         12              
// ---- END VEXCODE CONFIGURED DEVICES ----

#include "vex.h"

using namespace vex;

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();
  
}
axo1otl
  • 13
  • 4
  • Well you have 2 `main()` functions and that violates the one definition rule. Related: [https://stackoverflow.com/questions/4192170/what-exactly-is-one-definition-rule-in-c](https://stackoverflow.com/questions/4192170/what-exactly-is-one-definition-rule-in-c) – drescherjm Sep 24 '21 at 12:07
  • 2
    Move `vexcodeInit();` into the top of the first `main` and delete the second `main`. In fact, delete everything below the first `main`. It's all redundant. – Ted Lyngmo Sep 24 '21 at 12:09

1 Answers1

2

You have two main functions in your code. You must have only one. Either this one:

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();
  
}

Or this one:

int main() {
  // register event handlers
  Controller1.Axis3.changed(onevent_Controller1Axis3Changed_0);
  Controller1.Axis2.changed(onevent_Controller1Axis2Changed_0);

  wait(15, msec);
  // post event registration

  // set default print color to black
  printf("\033[30m");

  // wait for rotation sensor to fully initialize
  wait(30, msec);

}

EDIT: As mentioned in the comments, move this line: vexcodeInit(); into the first main of your code and delete the second main.

Your final file should look something like this:

#include "vex.h"
  
// Allows for easier use of the VEX Library
using namespace vex;

float myVariable;

// "when Controller1 Axis3 changed" hat block
void onevent_Controller1Axis3Changed_0() {
  Motor1.setVelocity(Controller1.Axis3.position(), percent);
  Motor2.setVelocity(Controller1.Axis3.position(), percent);
  Motor1.spin(forward);
  Motor2.spin(forward);
}

// "when Controller1 Axis2 changed" hat block
void onevent_Controller1Axis2Changed_0() {
  Motor11.setVelocity(Controller1.Axis2.position(), percent);
  Motor12.setVelocity(Controller1.Axis2.position(), percent);
  Motor11.spin(forward);
  Motor12.spin(forward);
}

// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name]               [Type]        [Port(s)]
// Controller1          controller                    
// Motor1               motor         1               
// Motor2               motor         2               
// Motor11              motor         11              
// Motor12              motor         12              
// ---- END VEXCODE CONFIGURED DEVICES ----
int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // register event handlers
  Controller1.Axis3.changed(onevent_Controller1Axis3Changed_0);
  Controller1.Axis2.changed(onevent_Controller1Axis2Changed_0);

  wait(15, msec);
  // post event registration

  // set default print color to black
  printf("\033[30m");

  // wait for rotation sensor to fully initialize
  wait(30, msec);
}
Ted Lyngmo
  • 93,841
  • 5
  • 60
  • 108
Zakk
  • 1,935
  • 1
  • 6
  • 17