- 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. You can feed it. Two ideas from before come back.
foreverwith await (1) secondsin it. This is the clock you built last week.- A
bestvariable that is set on the green flag only. It is 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
A game needs an ending. Say the number can go anywhere for ever. Then there is nothing to avoid. So there is nothing to play.
Today’s Topic 3 min
wait until <>. This block waits until something becomes true.- An ending with a sad costume, a sentence, and stop all.
- A
dayscounter with its own clock. - A best run that stays for the next player.
Learning outcome
By the end of this lesson you will be able to:
- End the game as soon as a variable reaches zero.
- Count how long the player lasted. Say it at the end.
- Keep the best run so far. Then 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 that for the Quiz Show referee. But one block does 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. Type0in the right. - Put it under its own green-flag hat. Put 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. The player is trying to last. So the score is how long they lasted. That 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 now run at once on the same sprite. One takes away food. One adds 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 Quiz Show used the same block.
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. Add four new scripts. Test them 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, add 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
days. Show it. - Add another green-flag stack with the day clock in it.
- Play a proper game. See how far you get.
Step 3 — the ending says the number
- Open your ending script. Put a
join [apple ] [banana]block in the say block. - Drag
(days)into the right half of the join. - Play again. Check that 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. Do not set it anywhere else.
- Add the comparison at the top of the ending script.
- Play three games. Do not press 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. Do you never come close to losing? Then it is too easy.
The pet never dies, even at 0.
The food is going past 0 and below it. Maybe the clock takes more than 1 at a time. Or the wait-until tests the wrong variable. Use <(food) < (1)> if you cannot find it.
The ending message flashes and disappears.
You used say [] with no seconds, then stop [all v]. Use say [] for (4) seconds.
The days keep counting after the pet has died.
They should not. stop [all v] ends them. Do you see them moving? Then the stop block is missing. Or it 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 goes on a green-flag stack with nothing else in it.
An ending worth reaching
Your game stops. Make it FINISH. Give it a face, a sentence with the number in it, and a reason to try again.
- The pet changes to show what happened.
- The sentence has the number of days in it.
- 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. There should still be 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 normal 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. Make the pet say something special when someone beats it.
- The record is on screen from the very first game.
- It does not reset when a new game starts.
- Beating it gets its own message.
- If you do not beat it, the pet says what the record 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 gets too hard.
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.
- You can see the pet grow as the days go by.
- It eats more each day than it did the day before.
- Nobody can last 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. It got a score too.
wait until <>waits until something becomes true.- The ending changes the face and says the number. Then it stops everything.
- In a game where you try to last, the score is a clock going up.
- A record is set on the green flag. It only changes when someone beats it.
- Wait until
- A block that stops 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. It is the score in a game where you try to last.
- Record
- The best anyone has done. It stays after a game ends.
Next lesson: three things to look after, not one. The face comes from the worst of them.