- Learnt28 min · a falling number, a pet that notices, a bowl
- Basic25 min · build your own pet
- Challenge 1–327 min · your pet, its face, its speed
- Extrabonus · a bowl that can be full
Review — where we got to 5 min
The Quiz Show is finished and shared. Two things from it come straight back today.
when this sprite clicked— the button hat from last week.<() < ()>and<() > ()>— comparing a variable with a number.
Quick-fire
Every project you have written does nothing at all until somebody presses something. What would make one change on its own?
Reveal the answer
A forever loop with a wait (1) seconds in it. The wait is what turns a loop into a clock.
Today’s Topic 3 min
- A variable that goes down on its own, using wait inside forever
- A second script that watches that variable and reacts
- Two costumes standing for two moods
- A bowl you click to put the number back up
Learning outcome
By the end of this lesson you will be able to:
- Make a number change by itself, at a speed you choose.
- Make a sprite react when that number gets low.
- Let the player push the number back up by clicking something.
Learnt — a number with a clock on it 28 min
1 · Wait, take one off, repeat
You know forever, and you know wait (1) seconds. Put one inside the other and you have a clock.
- Make a variable called
food. Leave it showing. - On the pet, start with
when flag clickedandset [food v] to (10). - Drag out
foreverfrom Control. - Put
wait (1.5) secondsinside it. - Under that, still inside, put
change [food v] by (-1). - Press the flag, then take your hands off the keyboard and watch.
when flag clicked
set [food v] to (10)
forever
wait (1.5) seconds
change [food v] by (-1)
end
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 pet notices
Now the number can get low, and nothing happens. Add a second script — running at the same time — whose only job is to look at it.
when flag clicked
forever
if <(food) < (5)> then
switch costume to [dog2-c v]
say [I am hungry!] for (1) seconds
end
end
<() < ()> is the less-than block, next to the greater-than one you used for the pass mark. It sits in Operators.
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 bowl
A pet you cannot feed is not a game, it is a countdown. The bowl is a sprite with the button hat you built last week.
- Add a Bowl sprite and put it in a bottom corner.
- Give it
when this sprite clicked. - Under that, put
start sound [Chomp v]. - Then
change [food v] by (3). - Run it and click the bowl. The number jumps up.
when this sprite clicked
start sound [Chomp v]
change [food v] by (3)
That is the whole game already. One script takes food away on a clock, one gives it back on a click, and a third looks at the number and decides what face to wear.
How to use this: Click the green flag, then click the bowl on the stage to feed the pet.
Basic — build your pet 25 min
One script at a time, and test after every one by pressing the flag and waiting.
Step 1 — the room
- New project, cat deleted.
- Choose an indoor backdrop. Room 1 or Bedroom 1.
- Add an animal sprite with at least two costumes. Dog2, Frog and Hedgehog all work.
- Look at the Costumes tab and pick the TWO that look most different. Write their names down. Dog2’s first two are almost the same picture; its third has a raised eyebrow and reads as worried from across the room.
Step 2 — the clock
- Make the
foodvariable. - Build the flag stack with the forever loop in it.
- Press the flag and watch for twenty seconds without touching anything.
- The number should reach 0 and keep going negative. That is fine for now.
Step 3 — the bowl
- Add a bowl or a food sprite and put it in a corner.
- Give it a flag stack that puts it in place, so it never wanders.
- Give it the clicked stack.
- Play for a minute. Try to keep the number above 5.
Step 4 — the mood
- On the pet, add the second flag stack with the if in it.
- Use your own costume names in the switch-costume block.
- Add an
elsehalf that switches back to the happy costume. - Play again. The face should follow the number both ways.
Step 5 — make it yours
- Change what the pet says when it is hungry.
- Add a sound to the bowl and a different one to the pet.
- Try feeding by 2 instead of 3 and see whether the game gets better or worse.
The number falls so fast I cannot read it.
There is no wait (1) seconds inside the forever loop, or it is below the change block and outside the loop. It goes inside, above the change.
The pet says “I am hungry” over and over without stopping.
That is what the loop does. It is not wrong yet — the say block waits one second, so it repeats about once a second. If you want it once only, that is next lesson’s problem.
Clicking the bowl does nothing.
The clicked stack is on the wrong sprite, or you are clicking while the project is stopped. Press the green flag first.
My pet stays sad even after I feed it.
The mood script has an if with no else. It knows how to become sad and has never been told how to become happy again.
Your pet, your room
Throw mine away. Pick your own animal, your own room and your own food.
- A different pet sprite from the one in the lesson.
- A backdrop that suits where it lives.
- A food sprite that suits the animal.
A face you can read across the room
Hide the number. Somebody standing behind you should still know whether the pet needs feeding.
- The variable’s tick box is unticked, so no number shows.
- Happy and hungry look completely different.
- It changes back both ways, not just one.
Teacher note — costume is not the only answer
A second costume is the obvious route, but set size to (70) %, set [color v] effect to (0) and a speech bubble all work too, and a pupil who combines two of them has made something better than the model answer. Accept anything that passes the across-the-room test.
Find the right speed
Your pet is either exhausting or boring. Change three numbers until it is neither, and write down what you chose.
- You have tried at least three different wait times.
- You have tried at least two different feeding amounts.
- You can say which combination you kept and why.
- You can play for a minute without either panicking or getting bored.
Teacher note — this is game balance, and it is a real job
Three numbers — the wait, the amount lost, the amount fed — decide whether the game is worth playing, and none of them can be worked out on paper. Insist on the writing-down part: the pupil who can say “1.5 seconds was too fast so I went to 2.5” has learnt something a pupil who fiddles until it feels right has not.
A bowl that can be full
Right now a player can click the bowl thirty times and go and make a drink. Stop them: feeding a full pet should do nothing but say so.
How to use this: Click the green flag, then click the bowl on the stage to feed the pet.
- The food never goes above 10, however many times the bowl is clicked.
- Clicking a full bowl says something rather than doing nothing silently.
- Feeding still works normally when the pet is hungry.
Teacher notes — one if around a block that already worked
when this sprite clicked
if <(food) < (10)> then
start sound [Chomp v]
change [food v] by (3)
else
say [The bowl is already full.] for (2) seconds
end
Note that 8 plus 3 is 11, so the cap is not exact. That is worth pointing out and NOT worth fixing at Level 1 — the honest fix is set [food v] to (10) in place of the change, and a pupil who proposes it has understood something real.
Going further: next lesson the number reaching zero starts to matter.
Summary 4 min
Today a project kept working while nobody was touching it.
wait (1) secondsinsideforeveris a clock.- One script changes the number; another one only ever looks at it.
- Two costumes are enough to show a mood.
- A bowl is a sprite with a clicked hat and one change block.
- Clock loop
- A forever loop with a wait in it, so something happens at a steady speed.
- Less than
- Asks whether the left number is smaller than the right one.
- Mood
- A costume chosen by looking at a variable, not by the player.
- Balance
- Choosing the numbers so the game is neither too easy nor too hard.
Next lesson: what happens when the food reaches nothing, and how many days you can keep the pet alive.