- Learnt27 min · a record each, a name, a scoreboard
- Basic25 min · build the wall
- Challenge 1–327 min · a readable board, records that hold, a dangerous button
- Extrabonus · a top three, in order
Review — where we got to 5 min
Three games behind three buttons, each with 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. Why can that block not be copied straight into the other two games?
Reveal the answer
It can — but each copy has to compare a different pair of variables. Three games means three bests and three comparisons.
Today’s Topic 3 min
- One record per game, checked at that game’s ending
ask [ ] and waitandanswer, to find out who is playing- Asking a question once instead of 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 that reads its numbers from variables.
Learnt — a record each, a name, a board 27 min
1 · Three records
The comparison is the same one from Topic 1.39, three times over, with different names in it each time.
- 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 comparison for that game only.
- Play each game twice: badly, then well.
- Check each record went up once and 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 on it belongs to the machine. One question at the start fixes that for the whole sitting.
- 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, 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, reads some variables, and has a way back.
- Add a sprite to hold the board. A Star or a blank sprite both work.
- On
when I receive [scores v]: switch to a plain backdrop and show. - Say each line in turn with
say (join [Jump Dash: ] (dash best)) for (2) seconds. - Show the home button, as on every other screen.
- 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. Leave them off the flag.
- Add one comparison to each game’s ending.
- Play each game twice and check the record behaves.
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, 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 every other screen.
Step 5 — play a whole session
- Six games in all, played by two different names — type one name, play three, then press the flag and type the other.
- Read the board at the end.
- Check every line matches what actually happened.
All three records show the same number.
The comparison was copied but not edited, so all three compare the same pair of variables. 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 is checking 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 touches them.
A board worth reading
Three speech bubbles one after another is slow. Make a board somebody can take in at a glance.
- All three records visible at once.
- Names beside numbers.
- Readable from a couple of desks away.
Records that hold
Try to knock a record down by playing badly. If you can, the comparison is wrong somewhere.
- Set a record in each game.
- Then play each game badly, on purpose.
- All three records survive.
- The names are still right afterwards.
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 also needs to be hard to wipe by accident. Build both.
- A way to clear every record.
- A question before it happens.
- Only one exact answer goes through.
- 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, with a new score sliding into the right one and pushing the others down, is a proper piece of programming.
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 middling score lands in the middle and pushes only 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, and the arcade remembers them.
- Each game keeps its own record, checked at its own ending.
- A record and its holder change together, inside the same if.
- Ask for a name once, when the variable is still empty.
- A scoreboard is a screen that reads variables and shows a way back.
- Record
- The best score anybody has managed. Never reset by the flag.
- Holder
- Whose record it is. Set at the same moment as the record.
- answer
- What the player typed. Copy it into a variable, or the next question wipes it.
- Confirmation
- A question asked before something that cannot be undone.
Next lesson: the last lesson of Level 1 — instructions, credits, and somebody else playing it.