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.

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.

    define myBlock

    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.

    define Make a square
        [Make the sides of the square 500 mm.]
        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.

    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