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 – counting our fortunes with mod


Now, we will refine how the teller determines what fortune to give by counting the questions and issuing a negative response for every fifth question. If you copied the list of Magic 8-Ball responses, as I did, then your negative responses are items 15 through 20 in the answers list. If you added your own answers to the list, move the negative responses to the end of the list. You can do this in a text editor and reimport the answers list. The steps are as follows:

  1. Our first task is to set up a variable to count how many questions the seeker asks so that we can calculate whether or not it's time to answer in negatives. Select the teller from the sprites list and create a new variable named question number and make it For this sprite only.

  2. Add the when flag clicked block to the scripts area.

  3. From the Variables palette, add the set question number to (0) block to the when flag clicked block. Now, we have a way to reset our counter at the start...