Learning Goals 3 min
By the end of this lesson you will be able to:
- Use
set [score v] to (0)andchange [score v] by (1), and say which is right for a job. - Use
show variable [score v]andhide variable [score v]from a script. - Recognise the add-versus-replace pattern you have now met six times.
Warm-Up 7 min
You have a box that holds a number. What you have not done yet is think carefully about the two ways of putting something in it — though you have met exactly this decision five times already.
Quick-fire puzzle
Aisyah pressed the space bar four times. Her friend Daniel pressed his four times too. Aisyah’s score read 4; Daniel’s read 1. What was different?
when [space v] key pressed
change [score v] by (1)
when [space v] key pressed
set [score v] to (1)
Reveal the answer
Aisyah used change, which adds to what is already there — 1, 2, 3, 4. Daniel used set, which replaces it, so every press put the box back to 1.
You have seen this exact distinction five times already: move and go-to, change-y and set-y, turn and point-in-direction, change size and set size, change volume and set volume. This is the sixth.
New Concept — add or replace, for the last time 15 min
There is genuinely nothing new here, and that is the point worth making. Once you recognise this pattern you can predict how a pair of blocks behaves before you have ever used them.
Blocks reference
| Block | Category | What it does |
|---|---|---|
set [score v] to (0) | Variables | Replaces the value. Does not care what was there. |
change [score v] by (1) | Variables | Adds to the value. Depends entirely on what was there. |
show variable [score v] | Variables | Puts the readout on the Stage. |
hide variable [score v] | Variables | Takes it off again. The value is untouched. |
The rule of thumb
Ask what the block should depend on. If the answer is “whatever it was before”, you want change. If the answer is “nothing — just this number”, you want set.
Scoring a point depends on the current score, so it is change. Starting a game does not depend on anything, so it is set.
Where each one belongs in a game
| Moment | Which block | Why |
|---|---|---|
| Game starts | set [score v] to (0) | The new score does not depend on the old one. |
| Player catches something | change [score v] by (1) | One more than whatever they had. |
| Player misses | change [score v] by (-1) | One less. Negative numbers work fine. |
| Bonus round doubles the target | set [score v] to (0) | A fresh start, regardless of history. |
Showing and hiding from a script
The tick box beside the variable turns the readout on and off by hand. The show and hide blocks do the same thing from inside a script, which means the display can change while the game runs.
That is more useful than it sounds: hide the score during a title screen, show it when play begins, hide it again at the end while a message appears.
Hiding is not resetting
Worth being clear, because it catches people. hide variable [score v] removes the display only. The number carries on existing and carries on changing, invisibly.
Why it matters
Every score, every life counter, every timer in every game you will ever build is these two blocks in the right places. Getting set and change the right way round is most of what makes a scoring system work.
Worked Example — a scoring system that behaves 15 min
We build the scoring half of the game — a reset, a way to score, and a readout that appears at the right moment.
Step 1 — Get it wrong first
Build this and click the flag three times, watching the readout.
when flag clicked
change [score v] by (1)
Step 2 — Fix it with set
Swap the block for a set and click the flag three more times. It reads zero every time, because setting does not care what came before.
when flag clicked
set [score v] to (0)
Step 3 — Add a way to score
On a separate script, use change so each catch adds to the running total.
when [space v] key pressed
change [score v] by (1)
Step 4 — Test the pair together
Press space six times, then click the flag. The score climbs to 6 and then drops cleanly to 0. That is a working scoring system in four blocks.
Step 5 — Add a penalty
Losing a point is the same block with a negative number — there is no separate block for subtracting.
when [m v] key pressed
change [score v] by (-1)
Step 6 — Control the readout from a script
Hide the score at the start, hold a title moment, then show it as play begins.
when flag clicked
hide variable [score v]
set [score v] to (0)
say [Get ready...] for (2) seconds
show variable [score v]
say [Go!] for (1) seconds
Step 7 — Prove hiding is not resetting
Press space a few times to build up a score, then hide the readout and press space several more times. Show it again — the number went up the whole time.
The display and the value are two different things. Forgetting that is a genuinely confusing bug to hunt.
What changed: your project has a scoring system that starts clean, counts properly, and shows itself when you want it to.
The full assembled scripts (your reference)
when flag clicked
hide variable [score v]
set [score v] to (0)
say [Get ready...] for (2) seconds
show variable [score v]
when [space v] key pressed
change [score v] by (1)
Try It Yourself — three small builds 12 min
Goal: Build a scorer where one key adds a point and another takes one away.
when [a v] key pressed
change [score v] by (1)
when [z v] key pressed
change [score v] by (-1)
Think: the same block does both jobs. There is no subtract block in Scratch because a negative number already does it.
Goal: Score in tens rather than ones, and add a bonus key worth fifty.
when [a v] key pressed
change [score v] by (10)
when [b v] key pressed
change [score v] by (50)
Think: nothing about the scoring system had to be redesigned to support a bonus. That flexibility is what a variable buys you.
Mini-mission: the title screen. Build a game opening where the score is hidden during a title, appears when play starts, and hides again at the end while a final message shows.
It works if: the score is hidden during the title and the ending, visible during play, and always starts at zero. Keep each stack under 8 blocks.
Think: if the player scores during the ending phase while the readout is hidden, does the number still change? Test it and find out what that tells you.
Mini-Challenge — set or change? 5 min
“Pick the right one, four times”
Here are four moments in a game. For each one, decide which block belongs there and be ready to justify it.
It works if:
- You choose a block for all four moments.
- You can justify each with one sentence about whether it depends on the previous value.
- You build all four and confirm each behaves as you predicted.
- You can name one other pair of blocks from an earlier lesson that works the same way.
Reveal the answers (teacher)
- Game starts — set to 0. Nothing before it matters.
- Catches one — change by 1. One more than before.
- Misses one — change by −1. One less than before.
- New round — set to 0, if the round starts fresh. Worth discussing: if the score carries across rounds, no block belongs here at all.
That last one is the interesting one, because the right answer depends on a design decision rather than a rule.
Recap 2 min
Set replaces, change adds — the same distinction you met with move and go-to, turn and point, size and volume. Ask whether the new value depends on the old one, and the answer tells you which block. Show and hide control the readout only, never the value, so a hidden score keeps counting. And a game needs its set block in the flag script or the score never starts from zero.
- set variable to
- Replaces a variable’s value with a fixed number.
- change variable by
- Adds to the current value. Negative numbers subtract.
- show / hide variable
- Turns the Stage readout on and off. Does not affect the value.
- Reset script
- A flag script that sets every variable to its starting value.
Homework 1 min
The wrong block on purpose. Find out exactly what each mistake looks like, so you recognise it when it happens by accident.
- Put a change block in your flag script instead of a set. Click the flag five times and note what happens.
- Put a set block in your scoring script instead of a change. Press the key five times and note what happens.
- Put both back correctly.
- Write one sentence describing each of the two symptoms.
when flag clicked
set [score v] to (0)
when [space v] key pressed
change [score v] by (1)
Bring back next class:
- Your two descriptions.
- Your answer to: “Name another pair of blocks from an earlier lesson that works exactly like set and change, and say what each one controls.”
Heads up for next class: SCR-L01-42 connects the score to something actually happening — a catch that the game notices by itself.