Creating a simple scoring system
💡 Having trouble with Scratch block assembly? Don’t know how to implement code logic? 🚀 Get Help Now
GameMaker456
Posted on January 20, 2024 • Intermediate
🎮 Need help with scoring system
Hey everyone! I’m working on my first game in Scratch where the player collects coins and defeats enemies. I want to add a scoring system that:
- Increases score when collecting coins
- Gives points for defeating enemies
- Shows the score on screen
I’m pretty new to variables and game mechanics. Any help would be appreciated! 🙏
ScratchCoder_Pro
Replied 2 hours later • ⭐ Best Answer
Great question @GameMaker456! Scoring systems are super fun to implement. Here’s a step-by-step guide that should help you out:
📊 Scoring System Flow
Here’s how the scoring system works:
🔧 Step 1: Create the Score Variable
First, create a variable called Score
and make sure it’s set to “For all sprites” so it’s accessible everywhere.
when flag clicked set [Score v] to [0]
💰 Step 2: Coin Collection System
For your coin sprites, add this code:
when flag clicked forever if <touching [Player v]?> then change [Score v] by [10] play sound [coin collect v] hide stop [this script v] end end
⚔️ Step 3: Enemy Defeat System
For enemy sprites when defeated:
// When enemy is defeated (example: when touched by player's attack) when I receive [enemy defeated v] change [Score v] by [50] play sound [enemy defeat v] hide
📺 Step 4: Score Display
Create a text sprite or use the built-in variable display:
Option A: Built-in Variable Display
- Right-click on the Score variable in the Variables palette
- Select “show” to display it on stage
- You can drag it to position it where you want
Option B: Custom Score Display
Create a text sprite with this code:
when flag clicked forever set [text v] to (join [Score: ] (Score)) go to x: [-200] y: [150] end
🚀 Step 5: Advanced Features (Optional)
If you want to get fancy, here are some cool additions:
Combo System:
// Add combo multiplier when flag clicked set [Combo v] to [1] set [Combo Timer v] to [0] forever if <(Combo Timer) > [0]> then change [Combo Timer v] by [-1] else set [Combo v] to [1] end end // When collecting items when I receive [item collected v] change [Score v] by ((base points) * (Combo)) change [Combo v] by [1] set [Combo Timer v] to [180] // 3 seconds at 60 FPS
High Score System:
when flag clicked if <(Score) > (High Score)> then set [High Score v] to (Score) broadcast [new high score v] end
Hope this helps! Let me know if you need clarification on any part! 😊
GameMaker456
Replied 30 minutes later
@ScratchCoder_Pro This is amazing! Thank you so much! 🎉
I got the basic scoring working perfectly. One quick question - how do I make the score display look nicer? Right now it just shows the raw number.
UIDesigner_Sarah
Replied 1 hour later
@GameMaker456 Great question! Here’s how to format large numbers nicely:
// Custom block: format score define format score (number) if <(number) > [999999]> then set [formatted score v] to (join (round ((number) / [1000000])) [M]) else if <(number) > [999]> then set [formatted score v] to (join (round ((number) / [1000])) [K]) else set [formatted score v] to (number) end end
This will show “1.2K” instead of “1200” and “2.5M” instead of “2500000”. Much cleaner! ✨
GameTutor_Mike
Replied 2 hours later
Love seeing beginners tackle game mechanics! 🎮 Here are some pro tips to make your scoring even better:
- Different point values: Give different items different point values based on difficulty to collect
- Bonus scoring: Add time bonuses or perfect completion bonuses
- Score feedback: Show floating text when points are earned
- Save high scores: Use cloud variables to save high scores online
Keep experimenting and have fun with it!
Vibelf_Community
Pinned Message • Moderator
🚀 Want to Level Up Your Game Development?
Great discussion everyone! For those looking to create even more advanced scoring systems, our community can help you implement:
- 🏆 Leaderboards
- 🎖️ Achievement systems
- 🧮 Complex scoring algorithms
- 🔓 Score-based unlockables
📚 Related Discussions
Ready to take your game development skills to the next level? Get personalized guidance from our expert tutors in the Vibelf app!