- Learnt27 min · a record each, a name, a scoreboard
- Basic25 min · build the wall
- Challenge 1–327 min · a clear board, records that stay, a risky button
- Extrabonus · a top three, in order
Review — where we got to 5 min
Three games behind three buttons. Each game has its own names for everything.
dash score,bounce score,tap score— one per game.- Every game ends with its own broadcast.
Quick-fire
Jump Dash already had a best score. Can you just copy that block into the other two games?
Reveal the answer
Yes. But each copy must check a different pair of numbers. Three games need three bests and three checks.
Today’s Topic 3 min
- One record per game. We check it when that game ends.
ask [ ] and waitandanswer. They find out who is playing.- Asking a question once, not every time.
- A screen with no game on it at all.
Learning outcome
By the end of this lesson you will be able to:
- Keep a record for each of three games.
- Store a name and put it beside a record.
- Build a scoreboard screen. It reads its numbers from variables.
Learnt — a record each, a name, a board 27 min
1 · Three records
We use the check from Topic 1.39 three times. Each time it has new names in it.
- Make three variables:
dash best,bounce best,tap best. - Never set any of them on the flag.
- On each game’s ending stack, add the check for that game only.
- Play each game twice: badly, then well.
- Check each record went up once and then stayed.
when I receive [dash over v]
if <(dash score) > (dash best)> then
set [dash best v] to (dash score)
set [dash holder v] to (player)
start sound [Cheer v]
end
How to use this: Click the green flag and watch. It plays two runs by itself — the record follows the better one, not the later one.
2 · Who is playing?
A record with no name belongs to nobody. One question at the start fixes that. The name stays until you stop.
- Make a variable called
player. - On the menu screen, ask
if <(player) = []> then. - Inside it,
ask [Who is playing?] and wait. - Then
set [player v] to (answer). - Press the flag and answer. Then go in and out of the menu three times.
when I receive [menu v]
show
if <(player) = []> then
ask [Who is playing?] and wait
set [player v] to (answer)
end
How to use this: Click the green flag, then type a name in the box and press Enter. Click the star to go back to the menu — it does not ask twice.
3 · A screen with no game on it
The scoreboard is the easiest screen in the project. It shows some words. It reads some variables. It has a way back.
- Add a sprite to hold the board. A Star or a blank sprite will work.
- Start with
when I receive [scores v]. Switch to a plain backdrop and show. - Say each line in turn. Use
say (join [Jump Dash: ] (dash best)) for (2) seconds. - Show the home button, like on the other screens.
- Click SCORES from the menu and read all three.
when I receive [scores v]
switch backdrop to [Chalkboard v]
show
say (join [Jump Dash: ] (join (dash best) (join [ by ] (dash holder)))) for (3) seconds
say (join [Bounce: ] (join (bounce best) (join [ by ] (bounce holder)))) for (3) seconds
say (join [Star Tap: ] (join (tap best) (join [ by ] (tap holder)))) for (3) seconds
How to use this: Click the green flag and read the board. Every line is built from two variables joined together — nothing to press.
Basic — build the wall 25 min
Six new variables today, and no new blocks at all.
Step 1 — the three records
- Make them. Do not set them on the flag.
- Add one check to each game’s ending.
- Play each game twice. Check the record works.
Step 2 — the three holders
- Make
dash holder,bounce holder,tap holder. - Set each one inside the same if as its record.
Step 3 — the name
- Make the player variable.
- Ask for it on the menu, but only when it is empty.
- Test it by pressing the flag twice.
Step 4 — the board
- Add the sprite and its receive stack.
- Build the three lines.
- Give it a home button, like the other screens.
Step 5 — play a whole session
- Play six games, with two names. Type one name and play three games. Then press the flag and type the other name.
- Read the board at the end.
- Check every line is true.
All three records show the same number.
You copied the check but did not change it. So all three check the same pair of numbers. Read all three side by side.
The name question comes back every time.
The set [player v] to (answer) is outside the if. Or the if checks the wrong variable.
The board says nothing at all.
The sprite is hidden. A hidden sprite still says things, but nobody sees the bubble.
The records vanish when I press the flag.
Something sets them to 0 on the flag. Records are like the best score in Topic 1.39. The flag never changes them.
A board worth reading
Three speech bubbles, one after another, is slow. Make a board you can read in one look.
- You can see all three records at once.
- Names go beside numbers.
- You can read it from two desks away.
Records that hold
Try to knock a record down by playing badly. If you can, the check is wrong.
- Set a record in each game.
- Then play each game badly, on purpose.
- All three records stay.
- The names are still right after.
Teacher note — the name that moves without the number
The classic bug: the holder is set outside the if, so a bad game leaves the record but changes whose it is. Ask pupils to check the name after every deliberate bad game.
The dangerous button
A scoreboard needs a way to wipe it. It must also be hard to wipe by mistake. Build both.
- A way to clear every record.
- A question before it happens.
- Only one answer works.
- Everything else leaves the board alone.
Teacher note — why this is worth ten minutes
Every real program has one of these. The pattern — a question, an exact answer, and nothing happening otherwise — is the same one behind every “are you sure?” a pupil has ever clicked.
if <(answer) = [CLEAR]> then is the whole implementation, and it is worth noting that Scratch does not care about capital letters here, so CLEAR and clear both work.
A top three, in order
One record is easy. Three places, in order, are much harder. A new score must slide into the right place. It pushes the others down.
How to use this: Click the green flag and watch five scores arrive one at a time. Each one slides into the right place and pushes the others down.
- Three places for one game, with three names.
- A new best pushes the old best down to second.
- A middle score lands in the middle. It only pushes down what is below it.
- A poor score changes nothing.
Teacher notes — the order the copying has to happen in
Third takes second before second takes first, or the same number ends up in both. It is the hardest ordering problem in Level 1 and it is worth letting pupils get it wrong once — the bug is very visible.
Lists make this much easier and they are Level 3. A pupil who says “there must be a better way” is right, and can be told so.
Going further: next lesson the cabinet gets instructions, credits, and an audience.
Summary 4 min
The scores now belong to people. The arcade remembers them.
- Each game keeps its own record. We check it when that game ends.
- A record and its holder change together, in the same if.
- Ask for a name once, when the variable is still empty.
- A scoreboard is a screen. It reads variables and has a way back.
- Record
- The best score anybody got. The flag never resets it.
- Holder
- Whose record it is. Set at the same moment as the record.
- answer
- What the player typed. Save it in a variable. If not, the next question wipes it.
- Confirmation
- A question we ask before something you cannot undo.
Next lesson: the last lesson of Level 1. Instructions, credits, and somebody else playing it.