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 – adding a score variable


To keep score, we need to set up a variable and add a conditional statement to increment the score when the ball touches a brick. Let's follow the given steps to add a score variable:

  1. From the Data palette, click on the Make a Variable button to display the New Variable dialog box.

  2. Type the word Score, and select the For all sprites option.

  3. Click on OK to add the variable. The Data palette displays several new blocks, and the Score reporter block automatically displays a monitor on the stage.

  4. Position the score monitor somewhere on the stage where it won't interfere with the gameplay, such as in a bottom corner.

  5. We will increase the score when a brick breaks, so let's work with the yellow brick sprite. Add the change () by () block from the Data palette after the broadcast (bounce) block in the when I start as a clone script. The default block values of score and 1 are correct.

  6. Click on the green flag and play the game. Each time the ball breaks a brick...