- 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 back today.
when this sprite clicked. This is the button hat from last week.<() < ()>and<() > ()>. They compare a variable with a number.
Quick-fire
Every project you have made does nothing until someone 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 turns the loop into a clock.
Today’s Topic 3 min
- A variable that goes down on its own. It uses wait inside forever.
- A second script watches that variable and reacts.
- Two costumes show two moods.
- You click a bowl 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. You choose the speed.
- Make a sprite react when that number gets low.
- Let the player click something to put the number back up.
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. Now you have a clock.
- Make a variable called
food. Leave it showing. - On the pet, start with
when flag clicked. Addset [food v] to (10). - Drag out
foreverfrom Control. - Put
wait (1.5) secondsinside it. - Under that, still inside the loop, 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, but nothing happens. Add a second script. It runs at the same time, and its only job is to look at the number.
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. It is next to the greater-than one you used for the pass mark. It is 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 just a countdown. The bowl is a sprite with the button hat you built last week.
- Add a Bowl sprite. 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. A third looks at the number and picks the face.
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
Build one script at a time. Test after each one. Press the flag and wait.
Step 1 — the room
- Start a new project. Delete the cat.
- 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. 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. It looks worried, even from across the room.
Step 2 — the clock
- Make the
foodvariable. - Build the flag stack with the forever loop in it.
- Press the flag. Watch for twenty seconds. Do not touch anything.
- The number should reach 0 and keep going below 0. That is fine for now.
Step 3 — the bowl
- Add a bowl or a food sprite. Put it in a corner.
- Give it a flag stack that puts it in place. Then it never moves away.
- 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, not 3. Does the game get 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. Do you want it only once? We fix that next lesson.
Clicking the bowl does nothing.
The clicked stack is on the wrong sprite. Or the project is stopped while you click. 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. Nothing tells it how to become happy again.
Your pet, your room
Throw mine away. Pick your own animal, room and 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. Someone behind you should still know if the pet needs food.
- The variable’s box is not ticked, 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 too much work or boring. Change three numbers until it is neither. 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 numbers you kept, and why.
- You can play for a minute. You do not panic or get 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 only say that it is full.
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 you click the bowl.
- Clicking a full bowl says something. It does not just do nothing.
- 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 touched it.
wait (1) secondsinsideforeveris a clock.- One script changes the number. Another one only 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. Something happens at a steady speed.
- Less than
- Checks if the left number is smaller than the right one.
- Mood
- A costume picked by looking at a variable. The player does not pick it.
- Balance
- Choosing the numbers so the game is not too easy and not too hard.
Next lesson: what happens when the food runs out. How many days can you keep the pet alive?