Skip to content
Writing Code > Vectors and Arrays

Vectors and Arrays

Edit This Page
Description: These group variables together.

Array Video Explanation:


Vector Video Explanation: (Resizable Arrays)


Example Usage for Vex!

Source can be found here. This is not the cleanest implementation of an autonomous route selector but it’s kind of waste full to spend too much time on making a pretty selector.

Definition of the vector:

// Creating a vector of displayable "AutonCards" that can be shown on the brain screen.std::vector<AutonCard> Cards = {    {"NO AUTO", "", NULL_AUTON}, // Note: this is using the {} constructor and auto deducing the type    AutonCard("DEBUG", "", Autonomous::debug), // This method is also useable    {"GOAL SIDE (QUAL)", "", Autonomous::goalSide},    {"RING SIDE (QUAL)", "", Autonomous::ringSide},    {"SOLO AWP (QUAL)", "[Profanity]", Autonomous::soloAWP},    {"5 Ring Side (ELIMS)", "I Quit", Autonomous::ringSideFive},    {"5 Goal Side (ELIMS)", "I'm Done", Autonomous::goalSideFive},    {"GOAL RUSH (ELIMS)", "", Autonomous::goalRush}};

Draw Logic:

// If ScreenDetector detects the button changed from released to pressed// or it's the inital loop (Basically if screen pressed)if (ScreenDetector.getChanged() &#x26;&#x26; ScreenDetector.getValue() || initial){  // Increment Index (This is the index that gets shown to the brain)  index++;                      if (index >= Cards.size())    {     // If Index is too large, then rollover to the start (Prevents index going out of range)    index = 0;  }    // Draw the card (This calls the function to draw the card information  // This draws the selected autonomous route's name and description  Cards[index].draw(redTeam);  }

Not an AD: Do you think that learning pointers should come before learning arrays? Feel free to contribute! πŸ˜„