- Learnt28 min · zero, wait until, and a day counter
- Basic25 min · a game with a score and an ending
- Challenge 1–327 min · an ending, a warning, a record
- Extrabonus · a pet that grows
Review — where we got to 5 min
Your pet gets hungry on a clock and you can feed it. Two ideas from before come back.
foreverwith await (1) secondsin it — the clock you built last week.- A
bestvariable set on the green flag only, from the Quiz Show.
Quick-fire
Your pet’s food went to −7 last week and nobody noticed. Why is that bad?
Reveal the answer
Because a game needs an ending. If the number can go anywhere for ever, there is nothing to try to avoid, and so there is nothing to play.
Today’s Topic 3 min
wait until <>— a block that sits still until something becomes true- An ending: a sad costume, a sentence, and stop all
- A
dayscounter on a clock of its own - A best run that survives the next player
Learning outcome
By the end of this lesson you will be able to:
- End the game the moment a variable reaches zero.
- Count how long the player lasted and read it out at the end.
- Keep the best run so far, so the next player has something to beat.
Learnt — zero, and how long you lasted 28 min
1 · The block that waits for a thing to be true
You could write this with a forever loop and an if in it — you did exactly that for the Quiz Show referee. There is a block that means the same thing in one line.
- Open Control.
- Find
wait until <>, under the wait block. - Drop
<() = ()>into its diamond. - Drag
(food)into the left side and type0in the right. - Put it under a green-flag hat on its own, with the ending under it.
when flag clicked
wait until <(food) = (0)>
switch costume to [dog2-c v]
say [You forgot about me...] for (3) seconds
stop [all v]
How to use this: Click the green flag to start it. Nothing else to press — watch it through, then use ↺ Reset to run it again.
2 · The score is time
This game has no points. What the player is trying to do is last, so the score is how long they lasted — which is another variable on another clock.
when flag clicked
set [days v] to (0)
forever
wait (3) seconds
change [days v] by (1)
end
Three scripts are now running at once on the same sprite. One empties the food, one fills the days, one waits for the end. None of them knows about the others.
How to use this: Click the green flag to start it. Nothing else to press — watch it through, then use ↺ Reset to run it again.
3 · The ending says what happened
“Game over” tells the player nothing. Put the number in the sentence with join [ ] ( ), the same block the Quiz Show used.
when flag clicked
wait until <(food) = (0)>
if <(days) > (best)> then
set [best v] to (days)
end
switch costume to [dog2-c v]
say (join [You looked after me for ] (days)) for (4) seconds
stop [all v]
How to use this: Click the green flag, then click the bowl on the stage to feed the pet.
Basic — a game with an ending 25 min
Carry on from last week’s pet. Four new scripts, tested one at a time.
Step 1 — the ending
- Add a new green-flag stack to the pet.
- Put
wait until <(food) = (0)>in it. - Under that, the sad costume, a sentence, and stop all.
- Test it by NOT feeding the pet. Time how long that takes.
Step 2 — the days
- Make a variable called
daysand show it. - Add another green-flag stack with the day clock in it.
- Play a proper game and see how far you get.
Step 3 — the ending says the number
- Open your ending script and swap the say block for a
join [apple ] [banana]one. - Drag
(days)into the right half of the join. - Play again and check the number in the sentence matches the one on screen.
Step 4 — the record
- Make a variable called
best. - Set it to 0 on ONE green-flag stack, and nowhere else.
- Add the comparison at the top of the ending script.
- Play three games without pressing the flag in between.
Step 5 — tune it
- Decide how long a really good run should be. Write the number down.
- Change the day clock until a good player gets close to it.
- Play it three times without trying hard. If you never come close to losing, it is too easy.
The pet never dies, even at 0.
The food is stepping past 0 into minus. Either the clock takes more than 1 at a time, or the wait-until is testing the wrong variable. Use <(food) < (1)> if you cannot find it.
The ending message flashes and disappears.
say [] with no seconds, followed by stop [all v]. Use say [] for (4) seconds.
The days keep counting after the pet has died.
They do not — stop [all v] ends them. If you see them moving, the stop block is missing or is inside an if that never runs.
My best is always the same as my last game.
set [best v] to (0) is in a place that runs every game. It belongs on a green-flag stack that also has nothing else in it.
An ending worth reaching
Your game stops. Make it FINISH: a face, a sentence with the number in it, and a reason to try again.
- The pet changes to show what happened.
- The sentence contains the number of days.
- It stays on screen long enough to read.
Warn them before it is too late
Losing should never be a surprise. Make the pet show it is in trouble while there is still time to save it.
- The warning starts before the food is gone.
- It stops when the player feeds the pet.
- It is different from the ordinary hungry face.
Teacher note — three states, not two
The mood script now has three answers, not two: fine, hungry, and in trouble. Testing from the LOWEST number up is the trap here, and it is the mirror image of the Quiz Show’s medal problem — there the tests had to run highest first. Ask the class why the two are opposite. The answer is that both are asking “which band is this in?” and the bands have to be tested from the end that is furthest from ordinary.
A record to beat
Put a record on the screen, keep it between games, and make the pet say something special when somebody breaks it.
- The record is on screen from the very first game.
- It does not reset when a new game starts.
- Breaking it gets its own message.
- Not breaking it says what the record still is.
Teacher note — the green flag is now a menu, not a start
A record that survives means the green flag can no longer be the thing that starts a game. This is the same discovery as the Quiz Show’s start button, arrived at from the other direction, and pupils who spot it themselves are ready for next lesson’s adopt screen.
A pet that grows
Every day your pet gets a little bigger and a little hungrier, so a run that was easy at the start becomes impossible.
How to use this: Click the green flag to start it. Nothing else to press — watch it through, then use ↺ Reset to run it again.
- The pet visibly grows as the days go by.
- It eats more each day than it did the day before.
- Nobody can survive for ever, however fast they click.
- The first thirty seconds are still easy.
Teacher notes — a number in the block instead of a number
when flag clicked
set [appetite v] to (1)
forever
wait (0.8) seconds
repeat (appetite)
change [food v] by (-1)
end
end
repeat (appetite) is the move worth stopping on: a repeat block whose count nobody typed. The pupils have used variables in say [Hello!] and in if <> then; this is the first time one has controlled how many times something happens.
when flag clicked
forever
wait (3) seconds
change [days v] by (1)
change [appetite v] by (1)
change size by (8)
end
And the growing is one extra block in the day clock. The pet gets visibly bigger, which means the difficulty is on the screen and not only in a variable.
Going further: next lesson the pet needs three things at once, not one.
Summary 4 min
A game needs an ending. Today yours got one, and a score to go with it.
wait until <>sits still until something becomes true.- The ending changes the face, says the number, then stops everything.
- When the point of a game is to last, the score is a clock going up.
- A record is set on the green flag and updated only when it is beaten.
- Wait until
- A block that pauses its script until the question in it becomes true.
- Game over
- The moment a rule is broken. It needs a face, a sentence and a stop.
- Day counter
- A variable that goes up on a clock. The score of a survival game.
- Record
- The best anybody has managed. It outlives a single game.
Next lesson: three things to look after instead of one, and a face that comes from the worst of them.