VSCode and multiple autonomous codes (C++)

I can’t figure out how to have multiple codes in VSC. I wanted to code for several different autonomous positions and have it all be in one workspace. However, every time I build the code, it gives me several different errors. It looks like all of the errors are that there were “multiple definitions of (xxx)” like “usercontrol()” and “autonomous()”. When I tried the individual files in another workspace by themselves, they worked. Is there a way for me to have all of them in one workspace so that I do not have to break it up?

errorcodes
This is an example of some of the error codes I received.

I am pretty sure you can’t have multiple vex projects open in the same workspace. You can use multiple files for one project though. If you want to make separate autons I highly recommend looking into making an auton selector as opposed to multiple programs.

You can have multiple projects (really folders) in a single workspace, you then select which one you want to build down on the status bar next to the play/stop controls.

the OPs issue is that they probably have multiple files in the same project that all have duplicate function names (multiple copies of main etc.)

3 Likes

I made an auton selector yesterday and I just have different functions with different auton codes then call the one I selected in the autonomous() function.
I select them using the pros::LCD system.

This was in Pros so ask jpearman if you need to do anything differently for Vexcode but it’s an aspect of C++ not Pros so it shouldn’t matter.
(I think the only difference is it’s vex.h not main.h.)

Here’s how I did it.

You have a .hpp file like this defining all your auton functions in the include folder.

#pragma once

void offensive();

void defensive();

If you define this .hpp in main.h and define main.h in the .cpp file with your auton functions you should be able to call the function from main.cpp or any file with main.h defined.

There is probably a better way but this is a basic explanation of the simple auton selector I made yesterday.

If this works for Vexcode as well I can do a more in-depth explanation if needed.

Hope this helps. :slight_smile: