Using Comment Blocks#

Using Comment Blocks

This tutorial covers how to use Comment blocks in VEXcode GO. By the end, you’ll know why and how to use comments to document a project.

Comment blocks let you add notes directly into your stack of blocks, found in the Logic - Comments category in the toolbox. They don’t affect how your project runs — they’re only there to help you and others understand it.

The default Comment block, below when started.#
    when started :: hat events
    [comment]

Programmers use comments to organize their code and make it easier to read and understand, both for themselves coming back to a project later and for others working on it. A single block’s name only describes that one block, but a comment can describe the behavior of an entire section of blocks at once — so you can understand what a stack of blocks does at a glance, without reading through each individual block.

For example, this project drives forward until it bumps into something, then backs away. As written, understanding that takes reading through every block.

A project that drives until it hits something, then backs away.#
    when started :: hat events
        drive [forward v]
        wait until <[bumper v] pressed? :: custom-led>
        stop driving
        drive [reverse v] for (100) [mm v] ▶

Adding a comment above each section describes its behavior, making the project easier to understand at a glance.

The same project, with comments describing each section’s behavior.#
    when started :: hat events
        [Drive forward until something is in the way.]
        drive [forward v]
        wait until <[bumper v] pressed? :: custom-led>
        [Back away from the object.]
        stop driving
        drive [reverse v] for (100) [mm v] ▶

After connecting your robot to VEXcode, select Start to run the project. The robot will drive forward, stop and back away once it bumps into something.

Screenshot of the VEXcode GO toolbar, with the Start button highlighted.