Designing Custom Blocks

Up until now, you used blocks that already existed. You will now learn how to build your own blocks. You will start by making a block that draws a square and you will name this new block draw square.
Script to draw a square

  1. Build the draw square block.
    To get the Block Editor, you can also click Make a block near the bottom of the "Variables" palette.
    To start, right-click (or control-click on a Mac) on the gray background of the scripting area and choose "make a block..." The video below shows how to start building the block. Finish it yourself, and press OK. The step-by-step instructions in the yellow section below give you more detail about what you are doing. make a block
Every block needs a palette (color), a title, a category (shape), and a script that defines its behavior.

You can use the draw square block exactly the way you have used other blocks. If you created the block as a blue Motion block, you will find it in the Motion palette.

pen down, draw square

Congratulations! You have just created your first custom block.

Practice building blocks.

  1. Define draw triangle to draw an equilateral triangle with the same side-length as the square you just drew.
  2. Define MyNameBackwards. When clicked, it should spell your name backwards. (Your related work from the previous page should be saved in "U1L2-ForLoops"; you can drag an entire script from the scripting area into the block editor.)
  House
  1. Create a script that uses your draw square and draw triangle blocks together to draw a "house" shape: a square with a triangular shaped roof sitting on top.
  2. Then create a new block draw house that is defined by the script you just made.