My Blocks#

My Blocks are used to create custom blocks.

My Blocks are used to create a sequence of blocks that can be used multiple times throughout a project.

My Blocks are made using the Make a Block button.

A rectangular button with rounded corners and a light gray border, labeled 'Make a Block' in bold, gray text, centered within the button.

My Blocks can have multiple parameters - text labels, numeric variables, and boolean variables - to add more functionality to your custom block.

a VEXcode stack of blocks containing a myBlock.#
    myBlock :: #ff6680

To use a My Block, attach the calling my block to a hat block. When the my block is reached in your project, the stack inside of the my block will run using the parameter values specified.

a VEXcode stack of blocks containing a define myBlock.#
    define myBlock

Note: Creating multiple My Blocks with the same labels and variables may cause errors when running your project in the Playgrounds.

In this example, a My Block is used to define making one side of a square. The My Block is then called 4 times to make all 4 sides of the square and finish the shape.

a VEXcode stack of blocks containing a define make a square block, a drive forward for 500 mm block, and a turn right for 90 degrees block. A separate stack of blocks contain a when started block, a repeat 4 times block, a make a square block, and an end block.#
    define make a square
    [Make the sides of the square 500mm.]
    drive [forward v] for (500) [mm v] ▶
    [Turn right 90 degrees to make it a square.]
    turn [right v] for (90) degrees ▶



    when started :: hat events
    repeat (4)
    [Make 4 sides to complete a square.]
    make a square
    end

My Blocks can also have custom parameters. In this example, the length of the square’s sides can be adjusted and will change in the My Block.

a VEXcode stack of blocks containing a define make a sideLength square, a drive forward for sideLength mm block, and a turn right for 90 degrees block. A separate stack of blocks contains a when started block, a repeat 4 times block, a make a 500 square block, and an end block.#
    define make a [sideLength] square
    [Drive forward for what the sideLength is set to in mm.]
    drive [forward v] for (sideLength) [mm v] ▶
    [Turn right 90 degrees to make it a square.]
    turn [right v] for (90) degrees ▶



    when started :: hat events
    repeat (4)
    [Type in the length of the square's sides.]
    make a (500)square
    end