- Learnt28 min · expect a number, then go and look
- Basic24 min · mend it yourself
- Challenge 1–327 min · a leak, a lie, and a second go
- Extrabonus · the countdown nobody saw
Review — the slice 5 min
- A design sheet is seven lines, and one of them is a single tick.
- Falling is a number you keep, not a glide.
- One My Block decides what happened; one variable holds it.
Quick-fire
Your lander reaches the ground too quickly. Where do you look first?
Reveal the answer
At a number, not at the blocks. “Too quickly” is a feeling. “60 ticks in the plan, 42 on the screen” is a fact, and a fact tells you which half of the code to open.
Today’s Topic 3 min
- Saying what you expect, in numbers, before you look
- Watching the Stage instead of the script — monitors and
say (join [fall is ] (fall)) - Halving the problem until only one script is left
- Changing one thing at a time, and checking after each
Learning outcome
By the end of this lesson you will be able to:
- Turn “it feels wrong” into two numbers that disagree.
- Find which script is lying by switching half of them off.
- Mend four bugs in a project you did not write.
Learnt — four moves 28 min
1 · A bug is a disagreement
A bug is not “something broken”. It is your plan and your program saying different things. So the first move is always the same: write down the number you expect. Last week’s flight took 60 ticks and arrived at 7.5. That is the plan.
How to use this: Click the green flag and watch the ticks monitor. It is the same flight as last week, from the same height.
2 · Make the numbers say themselves
You cannot read a running loop. You can make it talk. Drag fall onto the Stage, and put one say inside the loop:
if <((ticks) mod (10)) = (0)> then
say (join (join [tick ] (ticks)) (join [: fall is ] (fall))) for (0.6) seconds
end
mod keeps it to every tenth tick, so the bubbles are readable instead of a blur.How to use this: Click the green flag and read the bubbles. Each one shows fall beside the number the plan expects.
That last sentence is the whole move. Twice, every tick rules out a wrong starting value and rules out the ground. It points at gravity itself.
3 · Halve the problem
When a project is too big to read, do not read it. Switch off half of it and ask the question again.
- Drag half the scripts out of the way, into the empty grey area.
- Run it. Is the bug still there?
- Still there? The bug is in the half you kept. Gone? It is in the half you dragged out.
- Put the half back, and halve the guilty half again.
Four rounds of that narrows sixteen scripts down to one. It feels slow and it is the fastest thing you can do.
4 · Change one thing
When you find it, change one block and run it again. Two changes at once and you will never know which one worked — or which one broke something else.
How to use this: Click the green flag. One block has been deleted since the first embed; nothing else was touched.
Basic — mend it yourself 24 min
Open your own lander from last week and put the doubled gravity in on purpose. Then find it, using the four moves and nothing else.
Step 1 — break it, and write the number down
- Duplicate
change [fall v] by (-0.125)inside the loop. - Before running it, write on paper: how many ticks do you expect?
- Run it. Write down what actually happened, next to your guess.
Step 2 — make it talk
- Drag
fallandticksonto the Stage. - Add the every-tenth-tick
sayfrom Learnt part 2. - Run it and read three bubbles. Is it wrong by a little, or wrong by double?
Step 3 — halve, fix, check
- Drag every script except the flight loop out of the way. Bug still there?
- Find the doubled block and delete one of the pair.
- Run it. Your number should now match the paper.
- Take the
sayback out — a mended project should be quiet.
My say bubble flickers and I cannot read it.
It is running every tick, thirty times a second. Wrap it in if <((ticks) mod (10)) = (0)> then and give it for (0.6) seconds.
The numbers look right but the game still feels wrong.
Then your plan is the thing that is wrong, not your code. That is allowed, and it is worth saying out loud: change the sheet, then change the blocks to match it.
I fixed it, and now something else is broken.
You changed more than one thing. Undo with Ctrl + Z until the game is back to one bug, and start again, one block at a time.
I cannot drag a script out of the way — it is stuck to the others.
You are dragging from the middle of a stack, which takes everything below it. Drag the hat block at the very top instead, and the whole script comes as one.
The tank that leaks
This lander burns fuel it never used. Find out where it goes — the gauge is the only witness.
- Watch the fuel monitor beside the flame.
- Count roughly how many ticks the engine is actually lit.
- Compare that with how much fuel disappeared.
How to use this: Click the green flag and watch the fuel monitor, not the rocket. Note when the flame is on and when it is not.
Teacher reveal — one block, one step too high
define hold (speed)
change [fuel v] by (-1)
if <<(fall) < ((speed) * (-1))> and <(fuel) > (0)>> then
change [fall v] by (0.375)
switch costume to (lander-thrust v)
else
switch costume to (lander v)
end
The spend is above the if, so it happens on every tick of the flight. Move it inside, next to the thrust it pays for. Note that it can also go below zero — a gauge that reads −26 is the bug telling you about itself.
The landing that was a crash
This one is worse than a crash: it is a game that lies to you. It says landed after an arrival nobody could survive.
- Let it fall with no engine at all and read the speed at the bottom.
- Compare it with the 2.5 on your design sheet.
- Find the question the game forgot to ask.
How to use this: Click the green flag. Nobody touches a key — watch the fall monitor at the moment it stops.
Teacher note
This is the most valuable bug on the page, because nothing about it looks wrong. The project runs, the wording is sensible, and the test is even half right. Ask: “how would a player ever report this?” The answer — “the game said I won and I did not” — is what a real bug report sounds like.
Fine once, broken twice
The first flight is perfect. The second one never starts — the lander sits at the top of the Stage doing nothing at all.
- Watch
stateandfuelacross both goes. - Ask what the second go inherited from the first.
- List everything a new flight must put back.
How to use this: Click the green flag once and watch both flights. The go monitor says which one you are on.
Teacher reveal — a new flight is a My Block
define new flight
go to x: (-60) y: (130)
switch costume to (lander v)
set [fall v] to (0)
set [fuel v] to (120)
set [state v] to [flying]
set [ticks v] to (0)
Every variable that changes during a flight has to be named here. The cure for “I forgot one” is to put them all in one block, so there is exactly one place to look — the same trick Lesson 3-43 used for a new round.
The countdown nobody saw
A lift-off countdown was built by counting loop turns instead of seconds. On the screen, nothing counted at all.
- Run it and watch the turns monitor.
- Work out how many pictures were drawn while it counted.
- Rebuild the countdown so a person can read it.
How to use this: Click the green flag and keep your eye on the turns monitor. Try to see it move.
Teacher note
Worth timing on the board. Thirty drawings a second is the budget every Scratch game lives inside, and next week is about spending it well.
Summary 5 min
- A bug is your plan and your program disagreeing about a number.
- Write the number you expect before you look at anything.
- Monitors and one
saybeat reading the script. - Halve the project until one script is left, then change one block.
- Counting loop turns is not counting time.
- Bug
- A difference between what a program should do and what it does.
- Reproduce
- To make the same bug happen again, on purpose.
- Halving
- Switching off half the code to find which half holds the fault.
- Reset
- Putting every variable back before a new go begins.
Hand in
Save your mended game. Write one line at the bottom of your design sheet: the bug that took you longest, and the move that found it.