- Learnt28 min · three needs, one mood, a pet that paces
- Basic25 min · build all three
- Challenge 1–327 min · readable buttons, a pet that says what is wrong, a fair game
- Extrabonus · a pet that sleeps
Review — where we got to 5 min
Your pet has food, a bowl, a mood, an ending and a record. Two ideas carry today.
- The clock loop: a wait and a change block inside a forever.
- The mood script: an if that reads a variable and picks a costume.
Quick-fire
One need means the whole game is “click the bowl before the number runs out”. What does a second need add?
Reveal the answer
A choice. With two things falling at different speeds, the player has to decide which to deal with first — and that decision is the game.
Today’s Topic 3 min
- Three needs, three buttons, three clocks at three speeds
- A mood that comes from the worst of the three
- Why three ifs in a row beats one if / else here
- A pet that paces when it is happy and stops when it is not
Learning outcome
By the end of this lesson you will be able to:
- Run several variables at once, each on its own clock.
- Choose a costume by checking several variables in turn.
- Make a sprite’s movement depend on a variable rather than on a key.
Learnt — three needs and one face 28 min
1 · The same clock, three times
You already have one. Two more are copies of it with different names and different waits.
- Make two more variables:
funandsleep. - Right-click your food clock and choose Duplicate. Twice.
- Change the variable in each copy using its dropdown.
- Give each one a different wait: 1.1, 1.7 and 2.3 seconds.
- Press the flag and watch all three fall at once.
when flag clicked
set [fun v] to (10)
forever
wait (1.7) seconds
change [fun v] by (-1)
end
Each need gets its own button, and each button is three blocks.
when this sprite clicked
start sound [Boing v]
change [fun v] by (4)
How to use this: Click the green flag, then click the bowl, the ball or the bed on the stage — one for each of the pet’s three needs.
2 · One face, three questions
The pet has one face and three things that can be wrong with it. The trick is to start happy and let any of the three spoil it.
when flag clicked
forever
switch costume to [dog2-a v]
if <(food) < (4)> then
switch costume to [dog2-c v]
end
if <(fun) < (4)> then
switch costume to [dog2-c v]
end
if <(sleep) < (4)> then
switch costume to [dog2-c v]
end
end
Why not an if / else?
- An if / else has two answers, and here there are three ways to be sad.
- Nesting three if / elses inside each other is nine blocks deep and unreadable.
- Setting happy first and then testing three times is flat, short, and easy to add a fourth need to.
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 · A happy pet moves
The last thing that makes this feel alive costs one if. A pet with enough fun paces up and down. A bored pet sits still.
- On the pet’s green-flag stack, add
set rotation style [left-right v]. - Add another green-flag stack with a forever loop in it.
- Inside the loop, put
if <(fun) > (4)> then. - Inside THAT, two glide blocks: one to the right, one back.
- Play it and stop feeding the ball. The pacing stops on its own.
when flag clicked
forever
if <(fun) > (4)> then
glide (1.5) secs to x: (120) y: (-30)
glide (1.5) secs to x: (-120) y: (-30)
end
end
set rotation style the pet walks the return leg upside down.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.
How to use this: Click the green flag, then click the bowl, the ball or the bed on the stage — one for each of the pet’s three needs.
Basic — build all three 25 min
Add one need completely, test it, then add the next. Never two at once.
Step 1 — the second need
- Make a variable called
fun. - Duplicate the food clock and change both dropdowns in the copy.
- Give it a different wait time.
- Add a Ball sprite, put it beside the bowl, and give it the three-block clicked stack.
- Play for a minute with two needs.
Step 2 — the third
- Do the same again for
sleep. - Its button can be any sprite — a bed, a moon, a plain button.
- Give it the slowest clock of the three.
Step 3 — the mood
- Open your old mood script. It only knows about food.
- Change it so it sets the happy costume FIRST, inside the loop.
- Then add three ifs, one per need.
- Test by letting each need run out on its own.
Step 4 — the pacing
- Add
set rotation style [left-right v]to the green-flag stack. - Add the pacing stack.
- Play, and watch the pet stop when it gets bored.
Step 5 — tune the three speeds
- Play a whole game and see which need you had to deal with most.
- Slow that one down.
- Play again. Repeat until no single button is the answer to everything.
My second clock changes the food, not the fun.
The duplicate kept the old variable. There are two dropdowns to change: the set block and the change block.
The pet is sad for ever, even after I feed everything.
The happy costume is set once at the top of the script, outside the forever loop. It has to be the first block INSIDE the loop.
The pet walks back upside down.
set rotation style [left-right v] is missing. It goes on the green-flag stack, once.
Clicking a button feeds the wrong need.
Two buttons were duplicated and only one dropdown was changed. Open each one and read its change block.
Three buttons anybody can read
Anybody sitting down at your game should know what all three buttons do without asking — and that includes you, a week from now.
- Each button looks like the thing it does.
- Each one makes its own sound.
- They are lined up somewhere they will not be clicked by accident.
Say what is wrong
A sad face does not say which need is low. Make the pet ask for the thing it actually wants.
- Each need has its own sentence.
- The pet asks for whichever one is lowest, not for all three at once.
- It says nothing at all when everything is fine.
Teacher note — comparing two variables
Asking for the LOWEST need means comparing two variables against each other, which is new: every comparison so far has had a typed number on one side.
if <(food) < (fun)> then
say [I am hungry.] for (1.5) seconds
else
say [Play with me!] for (1.5) seconds
end
That handles two. Three is harder and a pupil who only does two has done the interesting part. Accept it, and let anybody who wants the third try — the honest answer needs nested ifs and it is a good stretch.
Make it a fair fight
Three needs should each matter. Tune the speeds until no single button is the answer to everything.
- The three clocks all run at different speeds.
- Over a whole game you press all three buttons roughly as often as each other.
- You can say which one you slowed down and why.
- You can survive two minutes, but only by concentrating.
Teacher note — count the clicks
Stand behind a pair and tally which button gets pressed. A game where one button gets twenty presses and another gets two is not balanced, and the tally is a far better argument than an opinion. This is the same skill as last lesson’s speed tuning, on three numbers instead of one.
A pet that sleeps
Clicking the bed should put the pet to sleep for a while. It stops getting hungry, it stops pacing, and none of the other buttons work — but sleep goes up fast.
- Sleeping is visible: a costume, a thought bubble, or both.
- Food and fun stop falling while the pet is asleep.
- The bowl and the ball do nothing while it sleeps.
- It wakes up on its own, without being clicked.
Teacher notes — a switch, and everything that has to ask about it
The tidy answer is one variable used as a switch — the same trick the Space Race will use for its countdown next month.
when this sprite clicked
set [asleep v] to (1)
change [sleep v] by (6)
wait (5) seconds
set [asleep v] to (0)
And every clock has to ask about it:
forever
wait (1.1) seconds
if <(asleep) = (0)> then
change [food v] by (-1)
end
end
The interesting failure is forgetting one of them. A pet that sleeps but still gets hungry is a bug the pupils will find by playing, and finding it is worth more than being warned about it. Ask them afterwards how many places had to change: the answer is every script that touches a need, which is why a switch is a bigger decision than it looks.
Going further: next lesson the pet gets a name and the game gets a front page.
Summary 4 min
One need was a chore. Three needs at three speeds is a game with decisions in it.
- Each need is a variable, a clock and a button. Three copies of one shape.
- Different speeds are what make the player choose.
- Set the happy costume first, then let three ifs spoil it.
- Movement can be decided by a variable instead of by a key.
- Need
- A variable the player has to keep up. This game has three.
- Mood
- A costume decided by looking at every need in turn.
- Rotation style
- Whether a sprite turns, flips, or stays upright when it changes direction.
- Balance
- Setting the speeds so every button matters as much as the others.
Next lesson: the pet gets a name you choose, a front page, and an ending that says how you did.