Time for action – drawing rows of bricks with custom blocks
The script to create the two rows of yellow bricks is working well; however, we're about to duplicate a lot of code and potentially have a really large and a difficult-to-manage script.
Let's break the duplicate code into a procedure, also known as a custom block in Scratch 2.0, as described in the following steps:
- From the Scripts tab of the brick, click on the More Blocks palette and click on the Make a Block button.
- In the New Block dialog that opens, type in
lay bricks
in the text field of the purple block and then click on OK to create the block. - After you create the block, Scratch places a block with the name lay bricks in the More Blocks palette, and in the scripts area, you now have a block titled define lay bricks.
- If you look closely at the code to create the bricks, you'll note that everything in the repeat blocks is an exact duplicate. Break the script apart and attach one of the repeat blocks to define...