Creating a My Block#

Creating a My Block

This tutorial walks you through creating a My Block in VEXcode GO, using a My Block that drives your robot in a square as an example. By the end, you’ll have a reusable My Block and a project that uses it to drive in a square.

My Blocks let you group a sequence of blocks you’ll want to use multiple times in a project, without needing to duplicate or recreate that sequence over and over. This can help break up longer projects to make them easier to work with.

  1. Go to the Logic - My Blocks category in the toolbox, and select Make a Block.

Screenshot of the toolbox with the Logic - My Blocks category open, and the Make a Block button highlighted.
  1. Change the Name field to square driving.

Screenshot of the Create My Block dialog, with the Name field highlighted, set to square driving.
  1. Select Create.

Screenshot of the Create My Block dialog, with the Create button highlighted.
  1. A define square driving hat block will appear in the workspace, and the My Block will appear in the toolbox. Any blocks you attach below the define block will run every time the My Block is used in a project.

An empty define square driving block.#
definir square driving :: custom

Note: If you delete a My Block’s define block from your workspace, it will also remove that My Block from your toolbox, and you will need to recreate it.

  1. Attach a drive for block and a turn for block below the define block, to drive and turn for one side of the square.

The define block, with drive for and turn for blocks attached.#
definir square driving :: custom
conducir [adelante v] por (200) [mm v] ▶
girar [derecha v] por (90) grados ▶
  1. As written, the My Block only drives and turns for one side of the square. To make it drive a full square on its own, wrap the drive for and turn for blocks in a repeat block set to 4.

The define block, with the drive for and turn for blocks wrapped in a repeat block.#
definir square driving :: custom
repetir (4)
conducir [adelante v] por (200) [mm v] ▶
girar [derecha v] por (90) grados ▶
  1. Attach a when started block, then pull square driving from the toolbox and attach it below. Your workspace now has both the define block and the when started block that calls it.

The full project — the square driving My Block, and a when started script that calls it to drive in a square.#
definir square driving :: custom
repetir (4)
conducir [adelante v] por (200) [mm v] ▶
girar [derecha v] por (90) grados ▶

cuando inicie :: hat events
square driving
  1. After connecting your robot to VEXcode, select Start to run the project. The robot will drive in a square.

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