1 / 20
Scratch Coding · Grade 5 · Chapter 6

Scratch Variables: Scorekeepers & Timers

Using computer memory to track game scores, lives, levels, and countdown timers.

Learning Goals

What We'll Build Today

GOAL 1

Variables Concept

Understand variables as labeled storage containers in computer memory.

GOAL 2

Set vs Change

Master resetting variables at game start and modifying them during gameplay.

GOAL 3

Game Timers & Lives

Build working scoreboards, 30-second timers, and player health bars.

Real-World Memory

How We Keep Score in Real Life

Think of a basketball game: the stadium scoreboard holds Home Team Score and Game Clock. Every time a basket is made, the score changes!

Discussion: What would happen in a video game if the computer couldn't remember your score or health?
Story Time

Noah's Unending Rocket Game

Noah built a super cool arcade game where a rocket dodges asteroids. But players complained: "There's no score, no health bar, and no way to know if you're winning!"

Noah realized he needed a container in Scratch to store points and count down seconds!
Core Concept

What is a Variable?

A Variable is a labeled box in computer memory that stores a piece of information (like a number or string) that can change over time.

Variable Name: [ score ]
Current Value: 15
Operation: change [ score ] by (1) ➔ New Value: 16
Visual Flow

The 4 Stages of a Variable

1

Create

Make a new variable in Scratch (e.g. Score).

2

Initialize

Set starting value (e.g. set score to 0 at flag click).

3

Update

Add/subtract points during game events.

4

Check

Use in conditionals (e.g. if score > 10 win!).

Scratch Block Distinctions

Set Variable vs. Change Variable

📌 set [score v] to (0)

OVERWRITES whatever value was inside the box with a brand new exact value.

Used for: Initializing at game start or resetting stats.

➕ change [score v] by (1)

ADDS (or subtracts) a value to the current amount inside the box.

Used for: Scoring points (+1) or taking damage (-1).

Code Example

Building a Coin Collection Scorekeeper

Here is how a coin sprite increases the player's score whenever collected:

when green flag clicked
set [score v] to (0) // Initialize!
forever {
  if <touching [Player v]?> then {
    change [score v] by (10)
    play sound [Coin v] until done
    go to [random position v]
  }
}
Game Mechanics

Building a 30-Second Countdown Timer

Creating a custom countdown timer variable in Scratch:

when green flag clicked
set [timer v] to (30)
repeat until <timer = 0> {
  wait (1) seconds
  change [timer v] by (-1)
}
broadcast [Game Over v]
Player Stats

Building a 3-Lives System

1. Initialization

when flag clicked ➔ set [lives v] to (3)

2. Collision Damage

if ➔ change [lives v] by (-1), wait 1 sec

Debunking Myths

The Forgotten Initialization Bug

Bug: You play a game, score 25 points, and lose. You click Green Flag to play again... but your score STILL starts at 25 points!
Fix: You must ALWAYS put set [score v] to (0) right under when green flag clicked!
Smartboard Voting

Trace the Variable!

Look at this code:
set [score v] to (10)change [score v] by (5)set [score v] to (2)
What is the final value of score?

Option A: 17
Option B: 2
Vote: Thumbs UP for Option A, Thumbs DOWN for Option B!
Spot the Bug

Why Did the Score Jump to 10,000?

forever [ if then change [score v] by (1) ]
The player touched the coin for half a second and gained 500 points instantly!
Discussion: Why did the score rocket up so fast? (Hint: Missing hide or wait block after scoring!)
Think-Pair-Share

Multiplier Power-Up Logic

In video games, grabbing a Star gives double points (2x multiplier) for 10 seconds!

Partner Task: How would you use a variable named pointsPerCoin to handle 1 point normally vs 2 points during double power-up?
Guided Practice

Building Game Victory Logic

Let's build a win-check script together on the smartboard!

when green flag clicked
forever {
  if <score >= 50> then {
    say [YOU WIN! HIGH SCORE!] for (3) seconds
    stop [all v]
  }
}
Hands-on Challenge

Clicker Game Challenge

Mission: Create a Scratch Clicker Game! Clicking the Cookie sprite increases Cookies by +1. At 20 cookies, unlock a second sprite that auto-clicks +1 per second!
Variables needed: Cookies and AutoClickers.
Quick Check · Question 1

Which block correctly adds 1 point to your score when you collect a gem?

Aset [score v] to (1)
Bchange [score v] by (1)
Cshow variable [score v]
Dmove [score v] steps
Click to reveal answer
Quick Check · Question 2

What happens if you forget to reset set [score v] to (0) at the start of a new game?

AThe game will not start
BThe player's old score from the previous game remains on screen
CThe score turns into a negative number
DScratch deletes the variable automatically
Click to reveal answer
Summary

Chapter 6 Key Takeaways

Looking Ahead

Next Stop: Mini-Game Project Part 1!

Now we have all the building blocks: Sequences, Loops, Conditionals, and Variables! In Chapter 7, we build our complete arcade game!

Exit Ticket: List 3 variables you would need for a Racing Mini-Game!