Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Multiplayer Racing Game Placing System
- bro77777
- Scratcher
3 posts
Multiplayer Racing Game Placing System
Im working on a scrolling Mario-kart esque racing game in scratch where you race against CPUs. But I have a problem: How do I make a placing system for the racers? Thanks!
hi this is my signature
iama furry
- LUKiCREATE
- Scratcher
17 posts
Multiplayer Racing Game Placing System
If I understand correctly, you could try using a list:
There I guess
when green flag clicked
delete [all v] of [places v] // For some reason Scratchblocks doesn't support "delete all of [list v]"
// Assign a player id to all players and CPUs
add (player id) to [places v] // Run this when a racer finishes
item (player id) of [places v] // Use this to retrieve the place of a racer
There I guess
Some cool projects
Check out other cool projects here: LUKiGAMES (studio)
Check out other cool projects here: LUKiGAMES (studio)
- bro77777
- Scratcher
3 posts
Multiplayer Racing Game Placing System
Im meaning like 1st place 2nd place etc.
hi this is my signature
iama furry
- Malicondi
- Scratcher
1000+ posts
Multiplayer Racing Game Placing System
Why not place them in the order of they finish? For example, say cpu finishes, they're #1 if nobody else has finished, then the player finishes, they're number 2 if only 1 person has finished and so on. Im meaning like 1st place 2nd place etc.
post #1000 post #100 i help in the forums post #1 post #500 0 second ninja
I recommend reading jvvg's essay about the scratch team before complaining, as it may change your opinion and provide insight on the topic.
coming soon :)
I recommend reading jvvg's essay about the scratch team before complaining, as it may change your opinion and provide insight on the topic.
coming soon :)
- MrKingofScratch
- Scratcher
100+ posts
Multiplayer Racing Game Placing System
(Sorry this took so long, I was going to explain a fancy sorting algorithm when I realized that I could make it way simpler)
We first have to give each racer a different ID that can identify them. This can be their name, or the color of the car, but I'll just use a number for now. I'm not exactly sure how to implement this without seeing your project first, but here's the main concept:
When each racer is “spawned” or created, you can set a variable to an ID. If you're using clones for the different racers, you will need to make the variable for this sprite only. This is a unique ID that will be used to tell which racer is in which place.
We will score the racers based on their time. We can store the scores in a list that i'll call scoreboard. We can also store the car IDs in a list.
Here's some code I whipped up:
When the race is started, use the
We also want to reset the lists at the start of the race:
Next, we have to get the racer's time when they cross the finish line. Add this code onto whatever code detects when a car reaches the finish line:
When the race is started:
I hope this helps! Let me know if you get stuck, and I will try to help you out.
We first have to give each racer a different ID that can identify them. This can be their name, or the color of the car, but I'll just use a number for now. I'm not exactly sure how to implement this without seeing your project first, but here's the main concept:
When each racer is “spawned” or created, you can set a variable to an ID. If you're using clones for the different racers, you will need to make the variable for this sprite only. This is a unique ID that will be used to tell which racer is in which place.
set [carID v] to [change this value based on the car (EX. blue or Mario or P1)]Next, we have to set each racer's score. Again, i'm not sure exactly how to implement this without seeing your project, but here's the main concept.
We will score the racers based on their time. We can store the scores in a list that i'll call scoreboard. We can also store the car IDs in a list.
Here's some code I whipped up:
When the race is started, use the
reset timerblock.
We also want to reset the lists at the start of the race:
delete (all v) of [scoreboard v]
delete (all v) of [carIDs v]
Next, we have to get the racer's time when they cross the finish line. Add this code onto whatever code detects when a car reaches the finish line:
add (carIDs) to [carIDS v]You can then use these values in a text engine or something like that to display the winners. Alternatively, you can keep it simple by displaying the scoreboard with a list. Instead of the above code, use this:
add (timer) to [scoreboard v]
When the race is started:
reset timerWhen car crosses finish line:
delete (all v) of [Scoreboard v]
add (join (join (carID) [: ]) (timer)) to [Scoreboard v]Now all we have to do is show the list when the race ends.
//this code will add the player and their time to the scoreboard list
show list [Scoreboard v]should do the trick! We also should hide it when the flag is clicked and/or when you go back to the menu if you have one in your game. You can use
hide list [Scoreboard v]==================================
I hope this helps! Let me know if you get stuck, and I will try to help you out.
- Discussion Forums
- » Help with Scripts
- » Multiplayer Racing Game Placing System