Bug Clinic · Lesson 9 · pairs · one card each

The Bug Clinic: five scripts, five hidden bugs

Diagnose before you fix. Each card below describes a short script that runs without error messages — and does the wrong thing. Your job is to name the symptom out loud, predict which block causes it, and then repair a copy of the script. Every bug here is one a real Year 7 programmer writes by accident at least once.

Build each card in Scratch from the description (the blocks are named, not scripted, so you practise finding them in the palette). Run it. Watch what actually happens instead of what you expected.

Card 1 — The song that never stops

On the green flag, a sprite plays a drum beat inside a forever block, and a second script is supposed to stop the music when the space key is pressed.

Symptom you will see: the drumming keeps going no matter how many times the space key is pressed.

Diagnose first: can a script inside forever ever reach a stop block? Where would the stop check have to live to run at all?

Card 2 — The score that forgets

A catcher game: set [score] to 0 sits under a when this sprite clicked block on the ball, change [score] by 1 happens when the catcher touches the ball, and the game ends after 30 seconds with a say [final score].

Symptom you will see: every new round, the first catch adds to last round's score — or the score resets in the middle of a round.

Diagnose first: when exactly does the reset run, and when should it run? What starts a round in this game?

Card 3 — The announcement nobody hears

A two-scene animation: the stage sends broadcast [scene2] after the narrator finishes, but Scene 2's backdrop never appears and the second sprite never enters.

Symptom you will see: the animation plays Scene 1 and then just stops, with no error message.

Diagnose first: a broadcast is a message to whoever is listening. Which block does the receiver need — and does its message name match letter for letter, including spaces?

Card 4 — The door that can't open

A maze game: the exit door opens when <touching [Door] and score = 10> is true, but the maze only ever awards 5 points, and the win script checks score = 10 while the score keeper adds 1 at a time.

Symptom you will see: you can collect every point in the maze and stand on the door forever — the condition never turns true.

Diagnose first: list every value the condition depends on. Can those values ever be true at the same moment in this game as it is built?

Card 5 — The chatbot with amnesia

A chatbot asks "What is your name?" with ask and wait, then later says join [Kia ora, ](name) using a variable called name — but nobody ever set name to anything.

Symptom you will see: the greeting comes out as "Kia ora," followed by nothing, no matter what the user typed.

Diagnose first: ask and wait stores the reply somewhere automatically. Which reporter block holds the user's last answer — and did anything ever copy it into name?

Logbook link

When your clinic bug is fixed, write the one-sentence rule it taught you in Logbook Section 9 — then add one bug from your own project, diagnosed the same way: symptom first, cause second, fix last.

Kaiako answer key — do not print for students

Card 1: the stop check lives inside the forever loop's twin script, or better, replace forever with repeat until <key (space) pressed?> and add stop [all sounds] after the loop. Rule: a script inside forever never "finishes" to reach later blocks.

Card 2: the reset is attached to the ball's click, so it fires mid-round whenever the ball is clicked, and it never fires at round start. Fix: set [score] to 0 belongs under when green flag clicked (or under the same event that starts the round). Rule: reset variables where the game starts, not where the sprite is touched.

Card 3: the receiver sprite has when I receive [scene 2] (with a space) while the stage broadcasts [scene2] — or the receiver block was never added at all. Fix: make the names match exactly and confirm a when I receive hat block exists on the sprite that must react. Rule: a broadcast nobody receives is a message into the void.

Card 4: the win condition demands score = 10 but the maze can only award 5, so the condition is unreachable. Fix: either award 10 points' worth of pickups or change the condition to score ≥ 5. Rule: a condition that can never be true is a locked door — check every value it depends on.

Card 5: nothing ever sets name; the reply sits in the built-in answer reporter. Fix: set [name] to (answer) immediately after the ask block. Rule: ask and wait puts the reply in answer — copy it if you want to keep it.