Trailblazer Robotics
Getting Started

Switching from Blocks to C++

If you've been coding in VEXcode Blocks, here's how to make the jump.

Why move at all?

Blocks are a great starting point, but every block is just a friendly wrapper around a line of C++. Once you outgrow them, when you want to write your own PID, your own odometry, your own state machines, you need text.

Think of it like: Blocks are like training wheels on a bike. They make balance easy while you focus on pedaling. Text C++ is taking the training wheels off. The bike is the same, but now you can go faster and turn sharper.

How to switch the editor

  1. Open VEXcode IQ.
  2. Click File → New.
  3. In the "Project Type" picker, choose C++ Project instead of "Blocks".
  4. You'll see a starter template with #include "vex.h" and an int main() function. That's where your code goes.
  5. Add motors, sensors, and devices using the Robot Configuration button, same as in Blocks, just attached to a C++ project.
Pro tip: in VEXcode IQ you can right-click your Blocks project and choose "Convert to C++". The editor shows you the equivalent C++ code for what you already built in blocks. Best way to learn the syntax.

The same program, both ways

Here are the four most common patterns. Read the block on the left, read the C++ on the right, and notice how they match.

1. Drive forward for 2 seconds

Blocks
when started
drive forward at 50%
wait 2 seconds
stop driving
C++
int main() {
  Drivetrain.drive(forward, 50, percent);
  wait(2, seconds);
  Drivetrain.stop();
}

2. If the bumper is pressed, stop

Blocks
if bumper pressed?
stop driving
C++
if (FrontBumper.pressing()) {
  Drivetrain.stop();
}

3. Repeat 4 times (drive in a square)

Blocks
repeat 4 times
drive forward 12 inches
turn right 90°
C++
for (int i = 0; i < 4; i++) {
  Drivetrain.driveFor(forward, 12, inches);
  Drivetrain.turnFor(right, 90, degrees);
}

4. Set a variable, then use it

Blocks
set speed to 50
drive forward at speed %
C++
int speed = 50;
Drivetrain.drive(forward, speed, percent);

The five "translations" that confuse beginners

1. Every statement ends with a semicolon

In blocks, you snap things together. In C++, the semicolon is the snap.

LeftMotor.spin(forward);   // semicolon = end of statement
Think of it like: a period at the end of a sentence. Missing one confuses the compiler the same way missing a period confuses a reader.

2. Curly braces { } group code

What was "everything inside this loop" in blocks is now "everything between { and }".

if (FrontBumper.pressing()) {
  // these two lines are inside the if
  LeftMotor.stop();
  RightMotor.stop();
}
// this line runs no matter what
Brain.Screen.print("done");

3. Variables must be given a type

In blocks, a variable just exists. In C++, you tell it what kind of value it holds.

int    speed = 50;       // whole number
double distance = 24.5;  // decimal number
bool   isHolding = true; // true / false

4. Capital letters matter

LeftMotor and leftmotor are two different things in C++. Blocks don't care about case; C++ does.

5. The compiler is strict but honest

Forget a semicolon? Wrong type? The compiler will tell you, with a line number. Read the error. It's almost always more helpful than it looks at first.

Think of it like: a strict teacher who points to the exact word you misspelled. Annoying at first, lifesaving once you trust it.

What to do next

Head back to the dashboard and start Week 1: Your First C++ Program. The patterns above will come up immediately, and now you know what they mean.

← Dashboard Start Week 1 →