On scrape 3.0, girlfriend might notification there is one form of variable: cloud variable. This alternative is accessible in develop Variable dialog. However, if you room a “New Scratcher”, you will not view this option. Therefore what is the function of making use of cloud variables? normally we might store highest video game score, the user name who gets the highest possible score to cloud variable. An ext than that, we could create multi-player cloud game. On YouTube, some YouTubers have actually uploaded wonderful tutorials to show the steps. If you would prefer to shot creating multiplayer cloud game, i strongly recommend you to clock the following video series. They space pretty useful for me to get acquainted with the design concept.

You are watching: How to make a multiplayer game on scratch

However, watching video is not enough for united state to learn things. As soon as I follow the over videos to architecture my first game, ns am still puzzled by some codes. Griffpatch is a good tutor, but the video clip is running pretty fast. This explains why I create this post. You could find part supplementary info to assist you much better understand the key issues of multiplayer cloud game.

I will share the project connect here in situation you would choose to read the code. The video game demo is shown below. Https://scratch.mit.edu/projects/477832015

Designing a scrolling platformer video game is a little bit complicated, but what around designing a multiplayer scrolling platformer game? Actually, all the multiplayer cloud game needs to settle the four issues:

Four vital Issues for Multiplayer Game

# 1. Encode and also Decode Cloud Variables

Per need from scratch 3.0 platform, just numbers are enabled to assign to cloud variable. If the local values contain letter or various other chars, we require to convert them come numbers, i beg your pardon is referred to as “encode”. ~ we obtain the value of cloud variable, we need to “decode” the value back to acquire its genuine meaning. Here, Griffpatch introduced a very convenient method: use “CODE” list as a recommendation to perform encode and decode. You can find the thorough steps in part 1 and component 2 of the videos, and I will not introduce them here.

#2. Assign a Player identifier to brand-new User

When a user clicks eco-friendly Flag button, the program requirements to enroll the user into the cloud game. So just how to entrust a Player ID come him/her? according to Griffpatch, the Player sprite’s identifier is marked by change “My Player #” and also its initial value is 0. The program uses a method, which i will mention at #4, to allocate a worth to “My Player #”. If “My Player #” is bigger 보다 0 after the allocation procedure, it way the user has actually joined the cloud game. If “My Player #” is still same to 0, it means the network game is totally packed. The user might still play the game in a single-player mode.

#3. Just how to display Other customers Playing the video game at the same Time?

How to display screen other football player on the stage in a multiplayer game? according to Griffpatch, the regimen creates another sprite, which might be referred to as “opponent players” or similar names. This sprite will get the same costume set as the Player sprite and also create number of clones. Those clones stand for the individuals playing the game at the very same time. What the program needs to do is to consistently decode cloud variables and assign x and y position, costume, username etc. To those foe player clones.

#4 just how to determine Those players Leaving the Game?

This is the many tricky component of the cloud game. What if part players leave the game? just how to determine who pipeline the game? The vital is to recognize the duty of each sprite. Because that Player sprite, the is responsible because that updating its worths to a specific cloud variable. For foe Player sprite, it is responsible for 3 things. One is to assign a Player ID come the Player sprite at beginning of the game. The 2nd is to repeatedly monitor i m sorry cloud variable keeps static for a period long enough to suggest that user being offline. The critical one is to decode the cloud variable worths to make foe player clones move and change costume.

Based on the over task assignment, let us rethink question #4. Assuming ns am the user “Tester1”. Ns play the game and is assigned a Player id of 3. If another user exiting the game once offered cloud2 variable, soon opponent player sprite will recognize the cloud2 variable coming to be static. The corresponding opponent player clone will hide itself. This clone will present again only after a new user rectal cloud2 variable and also updates it.

Now, assuming we space still user “Tester1”, yet we exit the game and also our populated cloud change cloud3 will save static. Various other users playing the game identify this revolution cloud3 and also their adversary player clone through Player i would of 3 will certainly be hidden. New users could use this variable.

In the complying with section, I will briefly present the included code in Player sprite and also Opponent Player sprite come implement cloud game.

Player Sprite

Player sprite is responsible because that encoding its worths to cloud variable. The method is the very same as what Griffpatch introduced, therefore I will certainly not explain further.


There is one minor adjust to Griffpatch’s code. Instead of using “round (timer * 10)” to represent a random value, I usage “pick arbitrarily (from 100 to 999)” to develop a arbitrarily value and also put it to the first item of the to-be-encoded characters. The advantage is that the number would constantly be 3-digit. Placing it to the first item provides it practically to it is in decoded and also used.


Opponent Sprite

For the opponent sprite, that shoulders more responsibility the cloud game functionality. I will explain those password segments one by one.

In “when green Flag clicked” segment, the regimen does part initialization work, such together clearing the list of “pre_value” and also “tick_value”, and also using 0 to refill lists. It sets MAX_PLAYER to 4 and Player # come 0.

when green Flag clicked

“when I receive Setup_opponents” code Segment, “when I start as a clone” password Segment

The an initial step for enemies Player sprite is to produce some clones, which are done in the password segment of “when I receive Setup_opponents”. In “when I begin as a clone” password segment, the program will to compare My Player # to Player #. Please keep in mind that Player # is a local variable, therefore, each clone will have a various Player #, ranging from 1 come 4.

If mine Player # is same to Player #, this clone is representing the current player. Since Player sprite is doing every the stuff, we just make this opponent Player clone totally transparent. For other Players, the routine sets their shade effect come 50 to differentiate them indigenous the existing player, and also then calls a block “Tick” to upgrade their appearance and also behavior. The whole idea because that this part follows Griffpatch’s instruction, therefore you can refer to the over videos as reference.

“when i receive determine ID” password Segment

In password segment of “when ns receive identify ID”, the routine will very first get the random worth of each Player and store it come a change “temp1”. After waiting for 3 seconds, it will gain the random worth of the same cloud variable. If the two values are the same, the regime concludes that the cloud change is not occupied, for this reason the current player is assigned to that Player ID.

Please keep in mind that Player # is a regional variable. Every clone will execute “when ns receive determine ID” password segment separately, so each cloud variable has actually been checked.

“Tick” Block Definition

The “Tick” block is responsible for decoding the data indigenous cloud variable and assigning the worths to the regional clones. The decode method is the same as what Griffpatch introduced. The only distinction is the Griffpatch’s code uses a regional variable dubbed “pre_value” to store each cloud variable’s previous value. Here, I usage a list dubbed “pre_value” to record cloud variables as various items. The benefit is the I might monitor the value of each cloud variable. If using neighborhood variable, we could not view their values at operation time.


After 0.03 seconds, the mite block will decode the cloud variable again, but this time, only inspect its an initial item: the arbitrarily value. If the value is the same as the in “pre_value” list, rise the corresponding item’s worth by 1 in “tick_value” list. If the worth is different, reset article in “tick_value” list to 0 and also assign the present value come “pre_value” item. In Griffpatch code, the again offers a neighborhood variable called “offline” to record the value. Making use of “tick_value” list provides it an ext convenient to record and also check values.

“begin decode that encoded” Block and also “value = decode the encoded” Block

The 2 blocks space responsible for decoding the cloud variable and storing it right into variable “value”. They simply follow Griffpatch’s method, therefore I will certainly not explain in detail.

“Position” Block

Finally, carry out not forget the this is a scrolling platformer game, therefore we must make the enemies Player clones scroll properly. Since cloud_x and also cloud_y are regional variables, each enemies Player clone might position themselves in different way on the stage.

See more: Take Cover Lyrics All Time Low - Take Cover ", All Time Low Debut New Song And Video, Take Cover


That is the significant code segments because that implementing multiplayer cloud game. Hope you understand better after analysis this post and know more about the strength of scrape 3.0. Enjoy the coding and have fun!

Please note: due to scratch 3.0 communication restriction, this multi-player cloud game might only work-related on the project creator’s own account. The means, if you create a multiplayer project and also login in top top different computer systems using the same account, you could play this multi-player game. However, other persons using various accounts might only play the video game in a single-user mode.