- Learnt27 min · the name clash, the name rule, a third game
- Basic25 min · fill all three doors
- Challenge 1–327 min · your third game, clean swaps, one look
- Extrabonus · tokens every game adds to
Review — where we got to 5 min
The cabinet works with one game in it. Adding a second game is a new kind of job.
- A screen is a broadcast. Every sprite answers it with show or hide.
- To leave a game, use
stop [other scripts in sprite v]. Then usedelete this clone.
Quick-fire
Both your games have a variable called score. What happens when they are in the same project?
Reveal the answer
There is only one score. Both games change the same number. Each one wipes out the other’s.
Today’s Topic 3 min
- What happens when two games share a variable name.
- A name rule that keeps three games apart.
- Messages belong to a game too. They clash in the same way.
- A whole third game, built from nothing, in ten minutes.
Learning outcome
By the end of this lesson you will be able to:
- Spot a name clash from the bug it makes.
- Name variables and messages so three games can share one project.
- Build a small game quickly from parts you already know.
Learnt — the clash, the rule, a third game 27 min
1 · Two games, one score
Bring Paddle Bounce in next to Jump Dash. Something odd happens. Neither game is wrong. But they both use one number, and there is only one of it.
- Use the backpack to bring the Paddle Bounce sprites into the arcade project.
- Change their hat blocks to
when I receive [bounce v]. - Play Jump Dash and get a good score.
- Go home. Open Paddle Bounce. Watch the number.
- Go home again and open Jump Dash. Your score has gone.
How to use this: Click the green flag, then click the left button and watch the score climb. Now click the right button — the score you just earned is gone.
2 · One name each
The fix is simple. Put the game’s name in front of everything that belongs to that game.
- Right-click each variable and rename it. Use
dash scoreandbounce score. - Scratch changes every block that used it, so nothing breaks.
- Do the same for lives, speed and level. For example,
dash livesandbounce lives. - Now the messages.
game overbecomesdash overandbounce over. - Play both games again. Check both numbers stay.
How to use this: Click the green flag, then click one button and then the other. This time both numbers survive, because each game has its own.
3 · A third game in ten minutes
Star Tap is small on purpose. You have used every block in it before. The whole game is nine blocks.
- Add the Star sprite.
- Start with
when I receive [tap v]. Then show, set the score to 0, and reset the timer. - Add
repeat until <(timer) > (20)>. - Inside it, go to a random spot. Then add
wait (0.8) seconds. - Make a second stack:
when this sprite clicked. Add a sound and a point. - Play it. Twenty seconds is longer than you think.
when I receive [tap v]
show
set [tap score v] to (0)
reset timer
repeat until <(timer) > (20)>
go to x: (pick random (-200) to (200)) y: (pick random (-130) to (130))
wait (0.8) seconds
end
hide
broadcast [tap over v]
when this sprite clicked
start sound [Collect v]
change [tap score v] by (1)
How to use this: Click the green flag, then click the star as many times as you can before the twenty seconds run out. It moves every 0.8 seconds whether you catch it or not.
Basic — fill all three doors 25 min
Rename things before you add anything. It is much harder later.
Step 1 — rename what you have
- Put dash in front of every Jump Dash variable.
- Every Jump Dash message too.
- Play Jump Dash once and check nothing broke.
Step 2 — bring the second game in
- Use the backpack to bring its sprites across.
- Give its variables and messages new names before you play it.
- Change its hat blocks.
- Give every one of its sprites a menu stack.
Step 3 — build the third
- Add the star and its two stacks.
- Give it a menu stack like everything else.
- Wire the third button to it.
Step 4 — the round trip
- Play all three, in every order you can think of.
- Check each score after playing the other two.
Step 5 — write it down
- Write down each variable and each message in the project.
- Mark which game each one belongs to. Or write shared.
- If you cannot label it, nothing uses it. Delete it.
Renaming the variable broke a block.
It did not. When you rename, Scratch fixes every block. If something broke, you made a new variable with a name like the first. You did not rename the first one.
Both games start when I click one button.
Two games are listening for the same message. Check the receive hats.
The star can be clicked on the menu.
It is hidden but its clicked stack still runs. A hidden sprite cannot be clicked in Scratch. So it is not hidden. Check its menu stack.
Star Tap never ends.
reset timer is missing. So the timer was already past 20 when the game started.
Make the third game yours
This Star Tap is the simplest version. Add one idea to it.
- Something new. Try a second thing to click. Or a thing to avoid. Or a star that shrinks.
- It still ends after twenty seconds.
- The score still makes sense.
Leave at the worst moment
Quit each game at the worst moment you can find. Then start it again. The game should start as if nothing happened.
- Leave in the middle of a hop, a rally, or a click.
- Leave while a game over message is on screen.
- Every restart begins just as it should.
Teacher note — the three awkward moments
Mid-clone is the one that breaks: rocks or crystals left flying. Mid-say leaves a speech bubble on the menu. Mid-wait leaves a script sleeping that wakes up during another game.
All three are fixed by the same menu stack, which is why this mission is a check and not new work.
One machine, not three
You built your three games weeks apart. Make them feel like they came from the same box.
- The home button is in the same corner in all three.
- Scores are shown in the same place in all three.
- The same sound means the same thing everywhere.
- Every game says its own name when it starts.
Teacher note — consistency is a design idea, not a tidy-up
The point is that a player learns the machine once. Ask the class where the home button is on their phone: it does not move between apps, and that is not an accident.
One number all three games pay into
Every score belongs to its own game. Add one that does not. It is a token count. It goes up whatever you play.
How to use this: Click the green flag, then click each of the three buttons in turn. Every game pays into the same tokens number, and it never resets.
- One shared variable. Every game adds to it.
- It is never reset when a game starts.
- Each game gives a fair number of tokens. A long game gives more.
- It shows on the menu, and only there.
Teacher notes — the fair rate, and what tokens are for
A twenty-second tap game and a three-minute bounce game should not pay the same. Ask pupils to time a game of each and set the rates from that — it is their first piece of balancing across two different things.
Tokens with nothing to spend them on are just another score. If a pupil asks what they are for, that is the right question, and the honest answer is that a shop needs more than Level 1 has. Level 2 builds one.
Going further: next lesson the scores stop belonging to whoever is sitting there and start belonging to a name.
Summary 4 min
Three games in one project. The hard part was not the games.
- A variable belongs to the project. If two games use one name, they share the number.
- Put the game’s name in front of everything that belongs to it.
- Broadcasts clash in the same way. You cannot rename them, so choose names first.
- A small game from parts you know takes ten minutes. It does not take a term.
- Name clash
- Two things use the same name. So they end up as one thing.
- Shared
- A variable or message that all the games use.
- timer
- The seconds since it was last reset. You can build a whole game on it.
- Consistency
- The same thing in the same place, all through a project.
Next lesson: a scoreboard, a name you type once, and three records to beat.