Discuss Scratch

Jake_twenty_eight
Scratcher
8 posts

Multiplayer cloud game Tech Demo [How to get more than 10 players online]

This project is a TEST, not a finished game.


This project is a demo, which theoretically allows up to some 300 players to join a cloud game at a time (though practically, the limit is usually more like 50 players.).

In this particular project the limit is 53 players.
If your game is very simple you could push it into the 200s of players, or if it's very complex you may need to push it back down a lot, to 20, for example.
https://scratch.mit.edu/projects/567707742/

To join, simply go to the project and press the flag. if anyone else is online, they will display as a person in a wheelchair.
(You can join multiple times in multiple tabs, even on the same account. But please try to keep it to 1 or 2 tabs, so that other people can join)

when green flag clicked
set [ myID] to ((☁ players) + (1))
(Above scratchblocks is just for illustration purposes and is not used in the code of my project)

Keep in mind this is only a demo, so you can't do much in this game, but using the basic principles of the method for multiplayer, the possibilities are endless!

Most people have a limit of 10 or so players in their multiplayer games, due to this being the maximum amount of cloud variables you're allowed.
But I want to share this method of storing cloud values, which can allow you to have a ton of players (depending on how much data your game needs!).

The basic principle is pretty simple. Take a single player's data, and format it in some consistent way, for example:
Player ID + X coordinate + Y coordinate

To make reading it simple, you'd make each value a fixed length, EG ID could be 2 characters, X could be 3, Y could be 3.

So, with that format, it would take 8 characters to store a single player's data. Cloud variables have up to 256 characters, so that's already 32 times smaller.

Next, we need to map each player to a spot in the cloud variable. That's what I'll use the ID for.
So let's say we have a player, and their ID is 4. You would put their data at 4*8 in the variable ( ID * charsPerPlayer).

With this method, we can store up to 32 players in a single cloud variable ( assuming we only need the ID, X, and Y. )
And you should remember this aswell: you have 10 cloud variables. If you dedicated all of them to just player data, you'd get 320 players. That's a huge improvement from just 10.

Of course, there's more data you'd probably need for a game other than x and y, and you might want to dedicate some cloud variables to things like leaderboards.

In this project I use 5 cloud variables, and have each player have a data with a size of 24 characters. So I can have max 53 players at a time.

(Also if you're digging in the code you might find some unused stuff like matchID, a text engine, etc, don't tell anyone about my online super scratch bros game idEA)

Last edited by Jake_twenty_eight (Sept. 10, 2021 08:05:24)

Jake_twenty_eight
Scratcher
8 posts

Multiplayer cloud game Tech Demo [How to get more than 10 players online]

bump
Jake_twenty_eight
Scratcher
8 posts

Multiplayer cloud game Tech Demo [How to get more than 10 players online]

Jake_twenty_eight wrote:

bump
bump
CodeDelta240
Scratcher
1 post

Multiplayer cloud game Tech Demo [How to get more than 10 players online]

Do players ever end up replacing other players data. Like when I get the variable and edit it to change my data but someone else does it at the same time someone's data will not be updated.
Jake_twenty_eight
Scratcher
8 posts

Multiplayer cloud game Tech Demo [How to get more than 10 players online]

CodeDelta240 wrote:

Do players ever end up replacing other players data. Like when I get the variable and edit it to change my data but someone else does it at the same time someone's data will not be updated.

Actually that's a pretty valid issue I haven't really addressed yet.
I haven't looked at this code in a while, but from what I can tell, currently in my project, the system is:
-If the area in the cloud variable corresponding to data is empty, then update the cloud with my data
-If my current data is different than my previous data, then update the cloud with my data

Most of my friends don't use scratch or don't have the scratcher rank, so I couldn't actually test it updating multiple players at once, like it would do in a real cloud multiplayer environment.

One idea you could use to get around this is to periodically check if your local data is different to your cloud data, and maybe add a random() block so that people aren't all checking at the same time, and if it's different then update your cloud data.

Also, sorry about the 5 day late reply, I don't actually check scratch that often lol
crumbthehog
Scratcher
92 posts

Multiplayer cloud game Tech Demo [How to get more than 10 players online]

endI'm having the same problem with my game. It's a racing platformer, and there are ten rooms with three players per room. I can't fit more then three players in a variable, otherwise like you said they end up overwriting each other. And even so it seems to juggle around who gets the best animation. Adding some buffer lists helped a bit, but I have to be careful not to go over the limit then. After a lot of modifications to the code, I finally got it to look good for three players per variable. This wouldn't work too well for games that need real time updates super fast. For example, I made a online pillow fight game with eight players. You need to have real time updates so they can hit you. Even so it takes about one second for them to respond to being hit. But for a racing game, you just need to see them and you generally don't interact with them. So just getting a smooth animation to other players is all I need.

Last edited by crumbthehog (Sept. 7, 2022 20:43:04)

crumbthehog
Scratcher
92 posts

Multiplayer cloud game Tech Demo [How to get more than 10 players online]

By the way, Cool project! Some poeple have gotten infinite player by juggling data through the players. This is only possible when it doesn't have to always update.
MyScratchedAccount
Scratcher
1000+ posts

Multiplayer cloud game Tech Demo [How to get more than 10 players online]

guides not allowed on forum. There is no guide area

Powered by DjangoBB