Book Image

Scratch 2.0 Beginner's Guide: Second Edition

By : Michael Badger
Book Image

Scratch 2.0 Beginner's Guide: Second Edition

By: Michael Badger

Overview of this book

Table of Contents (18 chapters)
Scratch 2.0 Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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:

  1. From the Scripts tab of the brick, click on the More Blocks palette and click on the Make a Block button.

  2. 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.

  3. 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.

  4. 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 lay bricks.

  5. Discard...