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();
}
CodePudding user response:
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);
}