Skip to main content

Lesson 3: Code Colorization in VEXcode VR Python

examples of colorized commands in the VEXcode VR Python

You now know the basics of getting started with VEXcode VR Python. You probably noticed that the lines of code in VEXcode VR Python become colorized when they are added to the Workspace. This colorization is a helpful visual tool that you can use while programming.

Knowing how VEXcode VR Python code is colorized can help you to quickly identify errors in project syntax or spelling mistakes, that might prevent your project from running as intended. Understanding code colors and their meaning will be valuable as you begin creating VEXcode VR Python projects.

Learning Outcomes

  • Identify and describe the colorization of code in VEXcode VR Python.
  • Identify how to indent commands in the Workspace, and the importance of doing so in a project.

Colorization of Code in VEXcode VR Python

When creating Text projects, the syntax, spacing, indenting, and spelling in your code in very important to ensure that your project runs as intended. The color coding present in the Workspace in VEXcode VR Python is an extra visual cue that you have entered your code into your project correctly. 

The colorization of code follows the following conventions: color coding conventions of the commands in VEXcode VR Python

Comments in a project are also colored green, but are preceded by a pound (#) symbol. image of comment with color in a project

When typing commands into the Workspace, if there is an unrecognizable component, it will remain black (like the user-created category). This can be a useful indicator as you are working, to prevent frustration or extra troubleshooting later on.

Use the cursor and keyboard to correct errors. As the components are recognized, they will be colorized correctly. This video clip shows an example of an incorrectly spelled command, with the errors corrected, and the color changes as they occur. 

Video file

The Importance of Indentation

In VEXcode VR Python, indentation is VERY important. The way that commands are aligned within a project contributes to the flow of a project. Improper indentation can result in a project not executing as intended, or not at all. Commands that are aligned with one another will run as a sequence. Commands that are indented within other commands (like the commands inside of a loop) will run within that structure. You will learn more about indentation throughout this course. image of a correctly indented project

 

Like the colorization of code, there are visual cues for proper indentation in VEXcode VR Python. The gray lines on the left side of the project, show how the project will flow. There should be a contiguous line from the main function through the entire project, as indicated by the arrow in this image. image of a project with the main function line indicator highlighted

Any subsequent loops or control structures will also have their own indicator lines, showing the start and end of the structure. In this example, the indicator line of the for loop is highlighted by the arrow. image of an indicator line highlighted by an arrow

Indenting Commands 

As your VEXcode VR Python project grow more complex, indentation will play an important role in how your projects are constructed. 

  • When adding commands to a project, use the 'Tab' button on the keyboard to indent lines of the project appropriately. Place your cursor at the start of the command, then press 'Tab' until the command is indented to the needed location.
  • To indent multiple commands the same way, select the commands you wish to indent, then use the 'Tab' button on the keyboard to move all of them at one time.
  • This video clip shows how to use the 'Tab' button to indent one line of code, and then multiple lines of code together, so that the project will execute correctly.
    • Notice that the indicator line for the for loop appears when the commands are correctly indented.  
      Video file