- Learnt28 min · friction, ask and answer, five pages, buttons as costumes
- Basic24 min · build the menu page
- Challenge 1–327 min · friction, the menu, all five pages
- Extrabonus · a Setting page
Review — where we got to 5 min
- The key pushes a number; one move block does the moving.
- Speed × 0.9 every loop is friction, and it is what makes the car coast.
- Five checkpoint posts, in order, make a lap honest.
Quick-fire
Your car keeps 90% of its speed each loop. What if you changed that to 80%?
Reveal the answer
It would slow down faster — more friction, like driving on sand. That one number is today’s first idea.
Today’s Topic 3 min
- Grass as friction, not as a wall
ask () and wait— letting the player type- A game with five pages
- Buttons as costumes, not as sprites
Learning outcome
By the end of this lesson you will be able to:
- Change how a car handles by changing one number.
- Ask the player a question and keep the answer.
- Build a menu from one sprite, and move between pages with broadcasts.
Learnt — friction and pages 28 min
Off the track, properly
Last week’s mission asked for a car that goes slower on the grass instead of being sent back to the start. You already have the block that does it — friction.
On the road you keep 90% of your speed each loop. On the grass, keep only 80%. That is the whole change.
if <touching color [#3FA34D]?> then
set [speed v] to ((speed) * (0.8))
set [steering v] to ((steering) * (0.7))
else
set [speed v] to ((speed) * (0.9))
set [steering v] to ((steering) * (0.85))
end
Letting the player type
In Sensing there is a block you have not used yet:
ask [How many laps to win?] and wait
set [laps to win v] to (answer)
answer.There is only one answer. Ask a second question and the first reply is gone.
So copy it out straight away — into (laps to win), player name, whatever you need it for.
A game has pages
Big games are not one screen. Ours will have five:
- Menu — 1 player, 2 players, Setting, How to Play
- Game Mode — Time Race or Lap Race
- Race Track — which track
- Game Play — the race itself
- Play Again — who won, and what next
Each page is a broadcast. Send it, and the game moves on.
The problem with buttons
In Level 1’s Lesson 10 you made buttons the obvious way: one sprite each. Four buttons, four sprites, four scripts. Fine.
Five pages of buttons is fifteen sprites, and fifteen scripts that are all nearly the same. You will lose track by the second page.
Buttons as costumes
Here is the better way, and it is the same idea as the checkpoints last week:
- One sprite per page. Call it Menu.
- One costume per button on that sprite, named after what it says.
- A My Block that places one button and clones it.
- Hide the real sprite. Only the clones are ever seen.
define Button (x) (y) (name) (size)
go to x: (x) y: (y)
switch costume to (name)
set size to (size) %
create clone of [myself v]
when flag clicked
hide
Button (0) (120) [Title] (90) :: custom
Button (0) (40) [1 Player] (80) :: custom
Button (0) (-20) [2 Players] (80) :: custom
Button (0) (-80) [Setting] (80) :: custom
Button (0) (-140) [How to Play] (80) :: custom
A clone finds out who it is
Every clone runs the same script, so every clone would broadcast the same thing. It has to ask its own costume which button it is:
if <<touching [mouse-pointer v]?> and <mouse down?>> then
wait until <not <mouse down?>>
if <(costume [name v]) = [1 Player]> then
broadcast [Game Mode v]
end
if <(costume [name v]) = [Setting]> then
broadcast [Setting v]
end
end
Making it feel like a button
Dim every button, and undim the one the mouse is on:
forever
if <touching [mouse-pointer v]?> then
clear graphic effects
else
set [brightness v] effect to (-15)
end
end
Two last fixes
The title lights up too. It is a costume on the same sprite, so it gets the same effect — and clicking it does nothing, which looks broken. Wrap the whole thing:
if <not <(costume [name v]) = [Title]>> then
end
Only the clicked button disappears. Each clone should leave when anybody makes a choice:
when I receive [Game Mode v]
delete this clone
Basic — build the menu page 24 min
Step 1 — the friction fix
In your race, wrap the two friction lines in an if / else on touching color [grass]?, with 0.8 and 0.7 in the grass half. Do it for both cars.
Step 2 — a new sprite called Menu
Paint your title as costume 1. Then paint one costume per button. Name each costume exactly what it says — you will be comparing against those names.
Step 3 — the Button block
Make a block with four inputs: x, y, name, size. Inside: go to, switch costume, set size, create clone.
Step 4 — place them
when flag clicked, hide, then one Button call per button.
Step 5 — the clone script
Show, go to front, then the forever loop: the hover effect, then the click check.
Step 6 — the two fixes
Wrap everything in the “not Title” check, and add a when I receive [Game Mode v] → delete this clone for each message.
Nothing appears at all.
The clone script needs show — the real sprite is hidden, and a clone starts hidden too because it copies the sprite.
Every button does the same thing.
You are missing the costume check, or two of your costumes have the same name. Show costume [name v] on the Stage and hover over each one.
One click skips two pages.
You have no wait until <not <mouse down?>>. The press is still going when the next page builds itself.
The buttons stay on screen after I click.
A clone only deletes on the messages it is told about. Add a when I receive [Game Mode v] stack for every message this page can send.
Grass that costs you
- More friction off the track, for both speed and steering.
- Both cars, each with their own numbers.
- Nothing resets and nothing teleports.
One sprite, one menu
- A menu page built from a single sprite with one costume per button.
- Buttons light up under the mouse; the title does not.
- Clicking any button clears the whole page.
- Each button sends a different message.
Teacher note
Some will have already built it with a sprite per button, and it will work. Do not undo it for them — ask them to add three more pages that way first. The refactor sells itself somewhere around the ninth sprite.
All five pages
The deck’s mission.
- Menu, Game Mode, Race Track, Game Play, Play Again.
- Two game modes: Time Race and Lap Race.
- Two tracks to choose from.
- The choices go into variables, so Game Play knows what to show.
Teacher reveal — pages are a state machine
A variable called page, holding one word, is worth adding even though nothing strictly needs it. Show it on the Stage while they click around. Suddenly the whole game is one word changing, and a page that fails to clear is obvious rather than mysterious.
This shape — one variable saying where you are, broadcasts moving you between states — is how menus, levels and game-over screens work in every language they will ever use.
A Setting page that works
Your menu has a Setting button. Make it do something.
- Ask how many laps win the race, and use that number.
- Ask for each player’s name, and show it on the Play Again page.
- Ask how fast the cars should be.
Summary 5 min
- Off the track is more friction — a cost, not a punishment.
ask () and waitfills one place calledanswer, and the next question wipes it.- A game is a set of pages, and a broadcast moves you between them.
- A page’s buttons are costumes on one sprite, cloned by a My Block.
- A clone reads its own costume to find out what it is meant to do.
- answer
- Where Scratch puts whatever the player typed. There is only one.
- Page
- One screen of a game. Only one is ever showing.
- Refactor
- Changing how code is written without changing what it does.
- Hover
- The mouse being over something without clicking it.
Hand in
Share your project and send the link to your teacher. Next lesson is the last of the Car Race — the pages and the racing finally join up.