- Learnt27 min · a title, a best score, a way back in
- Basic25 min · build the front door
- Challenge 1–327 min · your title, a best that holds, the stranger test
- Extrabonus · a how-to-play screen
Review — where we got to 5 min
Three lessons in, the game has everything except a way to meet it.
- Rocks on the ground, bats and stars at hop height, and a speed that climbs.
- A score, three lives, and a
game overbroadcast.
Quick-fire
The Quiz Show had a start button too. What did pressing the green flag do in that project?
Reveal the answer
It set the screen up and then waited. The flag builds the room; the button opens the door.
Today’s Topic 3 min
- A title screen, and a game that does not start until it is asked to
- Moving scripts from
when flag clickedtowhen I receive [play v] - A best score that is not reset by the flag
- Ending a game back where it started, so there is always another go
Learning outcome
By the end of this lesson you will be able to:
- Start a game from a button instead of the green flag.
- Keep a best score across games in one sitting.
- Come back to your project cold and use it with nothing but the Stage to go on.
Learnt — a title, a best, and a way back in 27 min
1 · The flag stops starting the game
Every game script currently begins on the flag. They all move to a message, and the flag is left with one job: show the title.
- Add a Button2 sprite in the middle-right. Name it
Play. - Give it
when this sprite clickedandbroadcast [play v], thenhide. - On every other sprite, swap
when flag clickedforwhen I receive [play v]. - Give the runner one flag stack that only sets up the title: show, go to the middle, say the name of the game.
- Press the flag. Nothing should move until you click the button.
when this sprite clicked
start sound [Pop v]
hide
broadcast [play v]
How to use this: Click the green flag — nothing happens, and that is right. Now click PLAY on the stage: the button vanishes and the rocks start coming.
2 · A number the flag must not touch
score belongs to one game. best belongs to all of them, so it is the one variable that is never set on the flag.
- Make a variable called
bestand show it. - Do not put
set [best v] to (0)anywhere. - On the game-over stack, ask
if <(score) > (best)> then. - Inside it,
set [best v] to (score)and say something loud. - Play three games and watch what best does after a bad one.
when I receive [game over v]
if <(score) > (best)> then
set [best v] to (score)
start sound [Cheer v]
say (join [New best: ] (best)) for (3) seconds
else
say (join [You cleared ] (score)) for (3) seconds
end
How to use this: Click the green flag, click the stage once, then press the space bar to end a run. Do it a few times and watch best climb but never fall.
3 · Ending where you started
The last thing a game over does is put the title back. Then the whole thing can be played again without anybody hunting for the flag.
- On the button, add
when I receive [game over v]. - Wait three seconds, then
show. - On the game-over stack, take out
stop [all v]and replace it with a broadcast the obstacles listen for. - On every factory, add a
when I receive [stop game v]stack withstop [other scripts in sprite v]andhide. - Play, lose, and play again without touching the flag.
when I receive [stop game v]
stop [other scripts in sprite v]
hide
delete this clone
How to use this: Click the green flag, then click PLAY. Click the stage and press the space bar to hop. When it ends, PLAY comes back — no green flag needed.
Basic — build the front door 25 min
This is the fiddliest build of the arc. Work sprite by sprite and test after each one.
Step 1 — the button
- Add it, name it, and place it where nothing else goes.
- Give it the clicked stack with the broadcast.
- Give it a flag stack that shows it and puts it in place.
Step 2 — move every script over
- Open each sprite in turn.
- Swap the flag hat for the receive hat on every game script.
- Press the flag and check the Stage stays still.
Step 3 — the title screen
- Give the runner a flag stack: show, go to the middle, say the game’s name.
- Make sure the obstacles are hidden until play starts.
Step 4 — the best score
- Make the variable and leave it alone on the flag.
- Build the if / else on the game-over stack.
- Play three games, including a deliberately bad one.
Step 5 — play again
- Bring the button back at the end of a game.
- Stop and hide every obstacle when the game ends.
- Play four games in a row without the flag.
Rocks fly across the title screen.
A factory is still on when flag clicked. Open the sprite and look at the hat block.
The second game has rocks left over from the first.
The old clones were never deleted. The stop-game stack has to reach the clones, not just the factory.
Best resets to 0 every time I press the flag.
There is a set [best v] to (0) somewhere. Find it and remove it.
Clicking PLAY starts two games at once.
The button was clicked twice, and it did not hide. Put hide above the broadcast.
A title screen worth looking at
The first screen is the only one everybody sees. Make yours say what it needs to.
- The name of the game, big enough to read.
- One obvious thing to click.
- Nothing moving that is not meant to be.
A best score that never goes down
Prove your best score works, in the one way that counts: by trying to break it on purpose.
- A good game, then a terrible one, then a middling one.
- The best is right after all three.
- Pressing the flag between games does not change it.
Teacher note — the test that finds the bug
Almost every pupil tests by getting better each game, which passes even when the code says set [best v] to (score) with no if around it. A deliberately bad second game is the whole test.
The cold test
You cannot see your own game properly while you still remember building it. Put time between you and it, then come back as a stranger would.
- Save it and close the project.
- Do something else for at least ten minutes.
- Open it again with every script window shut, so only the Stage shows.
- Play two whole games, following only what is on the screen.
- Write down every moment you had to stop and think.
- You start it without opening a script.
- You work out the controls from the screen alone.
- You know the moment you have lost.
- You play a second game without hunting for the flag.
Teacher note — why the gap matters more than the tester
The value of this mission is in the ten minutes of forgetting, not in who is holding the mouse. A pupil who tests immediately is testing their memory of the build, and their memory always knows what to press.
If two pupils happen to be at the same stage, swapping projects works too — but nobody waits for that, and the cold test alone is worth full marks.
The write-up is the deliverable: what the tester did, where they stopped, and what got changed afterwards.
How to play
Add a second door to your title screen: a page that explains the game, and a way back from it.
How to use this: Click the green flag, then click HOW TO PLAY on the stage. Read it, then click the home button to come back.
- A second button on the title screen.
- A screen that explains the controls and the scoring.
- A way back to the title that always works.
- You cannot get stuck on any screen.
Teacher notes — the third screen problem
Two screens is one broadcast each and easy. Three is where pupils meet the real problem: every screen has to hide everything belonging to the other two, and it is hiding that gets forgotten, not showing.
The tidy answer is one when I receive [menu v] stack per screen on every sprite, each one either showing or hiding it. Long, boring, and completely reliable — which is a fair description of a lot of real programming.
Going further: the next arc is a ball that never stops, and a paddle that has to be somewhere.
Summary 4 min
Jump Dash is finished, and it is the first game in the course with a front door.
- The flag builds the title. A button starts the game.
- Every game script listens for a message instead of the flag.
- A best score is the one variable the flag must not touch.
- A game that ends back at its title never needs the flag twice.
- Title screen
- The first screen. A name, a picture, and one thing to press.
- Best
- The highest score so far. Survives a game ending; does not survive closing Scratch.
- Screen
- A broadcast, and a set of sprites that show or hide when it arrives.
- Stranger test
- Watching somebody play with no help, and writing down where they stop.
Next lesson: a new arc — a ball that never stops moving, and a paddle that has to be in the right place.