Make a Game 🎮
beginner20 XP
Keep Score with Variables
Catch falling apples and count your points.
Keep Score with Variables 🍎
Games need a score! A score is a number that changes. In Scratch, we keep it in a variable, a box with a name.
Make a variable
- Click Variables (dark orange).
- Click Make a Variable and name it score.
Apples fall from the tree 🌳
Put this script on the Apple:
when flag clicked
set [score v] to (0)
forever
go to x: (pick random (-200) to (200)) y: (170)
repeat until <<touching (Bowl v)?> or <(y position) < (-170)>>
change y by (-5)
end
if <touching (Bowl v)?> then
change [score v] by (1)
end
end- set score to 0 starts the game fresh.
- pick random puts the apple somewhere new each time. 🎲
- change score by 1 adds a point when the bowl catches it!
Move the bowl
Put this on the Bowl:
when flag clicked go to x: (0) y: (-140) forever set x to (mouse x) end
The bowl follows your mouse left and right. 🖱️
🛠️ Build it!
- Pick the Apple and Bowl sprites.
- Make the score variable.
- Build both scripts, then play! How many can you catch?
⭐ Bonus: use change y by (-8) to make the apples fall faster. Harder!
🍏 Fun fact
Farmers pick apples in the fall. Some apple trees can live for 100 years!
🛠️
Build it in Scratch!
Open Scratch in a new tab, find the blocks shown above (they're the same colors!), snap them together and click the green flag. Then try the challenge ideas in the lesson.
Open Scratch ↗Scratch is free and made by MIT for kids. You can build without an account. To keep a project, ask a grown-up to help you sign in, or use File → Save to your computer.
Quick check
01/4
What is a variable?