Do you need to keep score in Scratch? If yes, keep reading! The instructions explain how to track the points earned by a player each time it touches a target.
About the Game
The directions listed below explain how to add scoring to an existing Scratch project. The game should have with a player and target sprite. Several scripts must already be built. For example, the player should have a script that controls its movement using the mouse pointer. As well, the target should be programmed to show in random spots. If your game design is different, you may need to adjust the scoring system to suit your Scratch project.
NOTE: These instructions are modified from the technology project TechnoCode, published by TechnoKids Inc. TechnoCode has programming activities for kids. The lessons include a game design coding unit. The seven assignments, guide students step-by-step through how to construct an entire game. To support learning, the unit has a planning sheet, example videos, sample scripts, programming challenges, game consultant checklist, coding journal log, Scratch quiz, Treasure Hunt skill review, and Variable extension activity.
About the Score Variable
The script you will build requires the use of a variable. A variable is a factor that can change. You will create a score variable. It will be used to hold the number of points.
A coding block will be used to increase the score by a specified number of points.
Another coding block will reset the score variable to zero when a new game begins.
About the Scoring System Script
Before making the variable and building the script it is important to understand how the scoring system script works. Study the script below.
Is the player touching the target? If yes, then increase the score by 2 points.
How to Keep Score in Scratch
Keep Track of the Score
- Open your saved game project in Scratch.
- Select the player sprite.
- From the Variables palette, click Make a Variable.
- Type score as the variable name. Click OK.
- Select the score variable to display it.
- Use your skills to build this script. How do you want the script to start? Notice that in the sample script below, it begins with when I receive play game. This is a broadcasted message that you may have already created. If the broadcast message was not made, you can use the when Go clicked Hat block.
Tip to Setting the Sensor Coding Block:
- View the Sensing palette.
- Drag touching mouse pointer into the if-then block .
- Click the arrow and select the name of the target.
Test the Scoring System
- Does the score increase each time the target is touched?
- Are too many points added when the player touches a target?
- If too many points are added when target touched, add wait 1 seconds after change score.
- Play a sound when the target is touched. You may need to trim the clip.
Set the Score to Zero When a New Game Begins
WHERE SHOULD THE CODING BLOCK GO? Notice where the set score to 0 block is located in the script above. It was placed after the when Go clicked Hat block of an existing script. Look at your scripts. Where should it be placed in your game?