Vex v5 pro code help

I’m trying to make a autonomous event but for some reason there is an error please help
image

Also If I chage the C to a lowercase c the dot becomes an error

add the command

vex::competition Competition;

to the start of the file

1 Like

Here’s the most simplistic competition template. You’ll need a loop inside of user control as well.

#include "vex.h"

using namespace vex;

competition Competition;

void pre_auton(void) {
}

void autonomous(void) {
}

void usercontrol(void) {
}

int main() {
  Competition.autonomous(autonomous);
  Competition.drivercontrol(usercontrol);

  pre_auton();

  while (true) {
wait(100, msec);
  }
}
5 Likes

With comments for those new to C++

// The #include "vex.h" tells the C++ "pre-processor" (a part of the compiling process) to read 
// the file called "vex.h" in the current directory and replace this line with the full contents 
// of that file.
#include "vex.h"

// This is a bit of a convenience statement so that the programmer doesn't have to
// prepend the "vex::" to things found in that namespace, which is a way to organize code
using namespace vex;

// This is declaring a variable called "Competition" which is of type "competition". In nearly
// all modern programming languages, the case of letters matters.  So "foo" is different than
// "FOO" is different than "Foo".  Because this is declared outside of any functions, this is
// known as a "Global Variable" and can be accessed in any "scope"
competition Competition;

// This defines a function. I don't recall if the declaration of "pre_auton" is done in "vex.h". If
// it is not, it is important that functions which are not declared in header files are defined
// before they are used.  If you were to move this function after the function "main", the
// compiler would complain.  You could then move it ahead of "main" or declare it, which is
// generally done in a header file, which would be "#include"-ed just like "vex.h"
void pre_auton(void) {
}

// Similar to pre_auton. Let's take a look at each component of this line.
// First, we see the first "void". This is the "return type" of the function. In this case, "void"
// indicates the function doesn't return a value.
// Second, we see "pre_auton" which is the name of the function.
// Third, we see the second "void" which indicates this function takes no arguments
// Combined, these 3 create the "function signature", which needs to be unique
void autonomous(void) {
}

void usercontrol(void) {
}

// For fun, we could create a new function:
// int doubleInput(int a) {
//   return a + a;
// }
// This function returns an "integer" (a number with no decimal places, so 1, 2, 3 or -1 or 0).
// This function takes 1 argument, which is also an integer.
// One could call this function in main by doing something like:
// int x = 1;
// int y = 0;
// y = doubleInput(x);  // The "value" of "x", in this case the integer 1, is passed into the function "doubleInput"'s first (and only) argument "a", so inside this call to "doubleInput", the value of "a" is 1

int main() {
  // This line tells the Competition object to call the function "autonomous" (the one between 
  // the ()) when the Competition switch indicates the autonomous part of the competition 
  // is active.  This does not actually run the autonomous() function at this time
  Competition.autonomous(autonomous);
  // If "Comptetition" had not been declared as a "Global Variable", the compiler would complain at this
  // point about not knowing what "Competition" was.
  Competition.drivercontrol(usercontrol);

  pre_auton();  // This runs whatever is in the pre_auton() function at this time

 // This is an infinite loop. 
 // This loop is necessary so that the Brain continues to run the program
  while (true) {  
  // This tells the Brain to go to sleep and let another task (such as the "autonomous" 
  // or "usercontrol" function to have the Brain's processor time for at least 100 milliseconds
    wait(100, msec);    
  }
}
6 Likes

i have had this problem before, and i fixed it by copying and pasting the code into a new document.