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 – creating a custom say fortune block


We're about to duplicate a script, so we're going to take this opportunity to create a custom block to select an item from the answers list based on a specified range of items.

  1. With the teller sprite selected, click on the Make a Block button from the More Blocks palette. Name the block say fortune in range:. Then, add a number input and change the input name to start range. Next, add a label with the text and; finish the block by adding another number with the name end range. The following screenshot shows the resulting define block:

  2. We want to use a similar set of blocks that we've already added to the if () then else block as we previously added to the when I receive (fortune) stack. The new expression will be say (item (pick random start range) to (end range) of (possible answers)) for (2) secs, as shown in the following screenshot:

  3. Let's put the custom block to use in the when I receive (fortune) script. Find the say () for () block...