On Scratch 3.0, you can notice tbelow is one type of variable: cloud variable. This option is accessible in Create Variable dialog. However before, if you are a “New Scratcher”, you will not see this choice. So what is the purpose of utilizing cloud variables? Typically we could save highest game score, the user name who gets the highest score to cloud variable. More than that, we can produce multi-player cloud game. On YouTube, some YouTubers have uploaded excellent tutorials to demonstrate the measures. If you would like to try creating multiplayer cloud game, I strongly recommfinish you to watch the adhering to video series. They are pretty beneficial for me to acquire acquainted with the style principle.

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

However, watching video is not enough for us to learn things. When I follow the over videos to style my first game, I am still puzzled by some codes. Griffpatch is an excellent tutor, but the video is running pretty quick. This explains why I compose this short article. You can uncover some supplementary information to help you better understand also the crucial issues of multiplayer cloud game.

I will share the task connect right here in instance you would choose to review the code. The game demo is displayed below. https://scratch.mit.edu/projects/477832015

Designing a scrolling platprevious game is a bit complex, yet what around designing a multiplayer scrolling platformer game? Actually, all the multiplayer cloud game requirements to solve the 4 issues:

Four Key Issues for Multiplayer Game

# 1. Encode and Decode Cloud Variables

Per need from Scratch 3.0 platdevelop, just numbers are enabled to assign to cloud variable. If the regional values contain letters or other chars, we should convert them to numbers, which is referred to as “encode”. After we acquire the value of cloud variable, we have to “decode” the value ago to obtain its real definition. Here, Griffpatch introduced a really convenient method: use “CODE” list as a reference to implement encode and decode. You might discover the in-depth steps in Part 1 and Part 2 of the videos, and I will not introduce them right here.

#2. Asauthorize a Player ID to New User

When a user clicks Eco-friendly Flag switch, the regimen demands to enroll the user into the cloud game. So exactly how to asauthorize a Player ID to him/her? According to Griffpatch, the Player sprite’s ID is marked by variable “My Player #” and also its initial value is 0. The regimen offers an approach, which I will certainly point out at #4, to allocate a value to “My Player #”. If “My Player #” is bigger than 0 after the alplace procedure, it means the user has joined the cloud game. If “My Player #” is still equal to 0, it indicates the network game is totally packed. The user might still play the game in a single-player mode.

#3. How to Sjust how Other Users Playing the game at the Same Time?

How to display screen other players on the phase in a multiplayer game? According to Griffpatch, the regime creates another sprite, which could be called “enemy players” or comparable names. This sprite will obtain the same costume collection as the Player sprite and also develop several clones. Those clones reexisting the users playing the game at the exact same time. What the regimen requirements to do is to consistently decode cloud variables and also assign x and y position, costume, username etc. to those foe player clones.

#4 How to Identify Those Players Leaving the Game?

This is the the majority of tricky part of the cloud game. What if some players leave the game? How to identify who leaves the game? The essential is to understand also the responsibility of each sprite. For Player sprite, it is responsible for updating its worths to a particular cloud variable. For Opponent Player sprite, it is responsible for 3 things. One is to assign a Player ID to the Player sprite at start of the game. The second is to consistently monitor which cloud variable keeps static for a duration long sufficient to show that user being offline. The last one is to decode the cloud variable values to make opponent player clones relocate and change costume.

Based on the over task assignment, let us rethink question #4. Assuming I am the user “Tester1”. I play the game and is assigned a Player ID of 3. If another user exiting the game when used cloud2 variable, shortly enemy player sprite will certainly determine the cloud2 variable ending up being static. The matching foe player clone will hide itself. This clone will certainly present aget just after a brand-new user occupies cloud2 variable and also updates it.

Now, assuming we are still user “Tester1”, yet we leave the game and our occupied cloud variable cloud3 will certainly save static. Other customers playing the game recognize this static cloud3 and their opponent player clone through Player ID of 3 will certainly be hidden. New users might usage this variable.

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

Player Sprite

Player sprite is responsible for encoding its worths to cloud variable. the strategy is the very same as what Griffpatch introduced, so I will not explain additionally.


Tright here is one minor change to Griffpatch’s code. Instead of utilizing “round (timer * 10)” to reexisting a random value, I use “pick random (from 100 to 999)” to produce a random worth and put it to the 1st item of the to-be-encoded characters. The benefit is that the number would always be 3-digit. Putting it to the 1st item makes it convenient to be decoded and also provided.


Opponent Sprite

For the adversary sprite, it shoulders even more obligation of cloud game functionality. I will certainly describe those code segments one by one.

In “as soon as Eco-friendly Flag clicked” segment, the routine does some initialization work-related, such as clearing the lists of “pre_value” and also “tick_value”, and using 0 to refill lists. It sets MAX_PLAYER to 4 and also Player # to 0.

once Environment-friendly Flag clicked

“as soon as I receive Setup_opponents” Code Segment, “as soon as I start as a clone” Code Segment

The first action for Opponents Player sprite is to create some clones, which are done in the code segment of “as soon as I obtain Setup_opponents”. In “when I begin as a clone” code segment, the regime will compare My Player # to Player #. Please note that Player # is a neighborhood variable, therefore, each clone will have a various Player #, varying from 1 to 4.

If My Player # is equal to Player #, this clone is representing the present player. Because Player sprite is doing all the stuff, we just make this Opponent Player clone fully transparent. For other Players, the program sets their shade effect to 50 to identify them from the existing player, and also then calls a block “Tick” to upday their appearance and habits. The whole concept for this part adheres to Griffpatch’s instruction, so you might describe the over videos as reference.

“once I get Determine ID” Code Segment

In code segment of “once I obtain Determine ID”, the routine will initially obtain the random value of each Player and keep it to a variable “temp1”. After waiting for 3 seconds, it will certainly get the random worth of the same cloud variable. If the two values are the very same, the routine concludes that the cloud variable is not populated, so the existing player is assigned to that Player ID.

Please note that Player # is a regional variable. Each clone will certainly execute “as soon as I receive Determine ID” code segment independently, so each cloud variable has been checked.

“Tick” Block Definition

The “Tick” block is responsible for decoding the data from cloud variable and assigning the values to the regional clones. The decode method is the very same as what Griffpatch presented. The only distinction is that Griffpatch’s code offers a local variable referred to as “pre_value” to store each cloud variable’s previous worth. Here, I usage a list referred to as “pre_value” to record cloud variables as various items. The advantage is that I might monitor the worth of each cloud variable. If using neighborhood variable, we can not view their worths at run time.


After 0.03 seconds, the Tick block will decode the cloud variable aget, yet this time, only examine its first item: the random worth. If the worth is the same as that in “pre_value” list, boost the matching item’s worth by 1 in “tick_value” list. If the value is various, reset item in “tick_value” list to 0 and also asauthorize the current value to “pre_value” item. In Griffpatch code, he aobtain offers a neighborhood variable referred to as “offline” to document the worth. Using “tick_value” list provides it even more convenient to document and inspect values.

“begin decode of encoded” Block and “value = decode the encoded” Block

The 2 blocks are responsible for decoding the cloud variable and storing it into variable “value”. They simply follow Griffpatch’s technique, so I will not describe in information.

“Position” Block

Finally, do not foracquire that this is a scrolling platformer game, so we need to make the Opponents Player clones scroll effectively. Due to the fact that cloud_x and cloud_y are neighborhood variables, each Opponents Player clone can place themselves in different ways on the stage.

See more: How To Make An Exploded View In Solidworks : Exploded Views, Exploded Views In Drawings


That is the major code segments for implementing multiplayer cloud game. Hope you understand also better after analysis this write-up and also recognize more around the power of Scratch 3.0. Enjoy the coding and have actually fun!

Please note: as a result of Scratch 3.0 platcreate restriction, this multi-player cloud game might only work on the task creator’s very own account. That implies, if you develop a multiplayer task and login in on various computer systems utilizing the exact same account, you can play this multi-player game. However before, other persons utilizing different accounts can just play the game in a single-user mode.