Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » ITopic: A guide on how to make a multiplayer game
- deck26
-
1000+ posts
ITopic: A guide on how to make a multiplayer game
Please don't spam.when green flag clicked
- D_i_a_v_l_o
-
500+ posts
ITopic: A guide on how to make a multiplayer game
How do you make the menu on the purple block..?
- minecraft74
-
16 posts
ITopic: A guide on how to make a multiplayer game
when green flag clicked
switch costume to [Multiplayer!! v]
say [:O] for (2) secs
play sound [2p v] until done
play sound [3p v] until done
play sound [4p v] until done



























































































































































































































- EncloCreations
-
500+ posts
ITopic: A guide on how to make a multiplayer game
I made a youtube series based on this https://www.youtube.com/channel/UCkPYZZ5k0axY170MaUVLKiQ
- Yoshi21105
-
17 posts
ITopic: A guide on how to make a multiplayer game
Whoa! That's big! I'll try this! You must have done tons of research!
- EncloCreations
-
500+ posts
ITopic: A guide on how to make a multiplayer game
nah i learned it all mahself in the scratch editor Whoa! That's big! I'll try this! You must have done tons of research!
- student6DCS
-
100+ posts
ITopic: A guide on how to make a multiplayer game
I don't really get it.nah i learned it all mahself in the scratch editor Whoa! That's big! I'll try this! You must have done tons of research!
- Turbo_Tomato
-
6 posts
ITopic: A guide on how to make a multiplayer game
How do you get the load and save block?
- EncloCreations
-
500+ posts
ITopic: A guide on how to make a multiplayer game
Its on a engine, watch my youtube series it explains it really well How do you get the load and save block?
- Turbo_Tomato
-
6 posts
ITopic: A guide on how to make a multiplayer game
I got the custom blocks (save, load) but it said unidentified, Help?
- Turbo_Tomato
-
6 posts
ITopic: A guide on how to make a multiplayer game
Its on a engine, watch my youtube series it explains it really well How do you get the load and save block?
What is your YouTube?
- EncloCreations
-
500+ posts
ITopic: A guide on how to make a multiplayer game
https://www.youtube.com/channel/UCkPYZZ5k0axY170MaUVLKiQIts on a engine, watch my youtube series it explains it really well How do you get the load and save block?
What is your YouTube?
- Penguin9090_new
-
500+ posts
ITopic: A guide on how to make a multiplayer game
Cool! But be prepared for
this iza 2 hardd iz there a ezer wai??
- EncloCreations
-
500+ posts
ITopic: A guide on how to make a multiplayer game
i try to make it easy… try… Cool! But be prepared forthis iza 2 hardd iz there a ezer wai??
- s-zhangcha
-
100+ posts
ITopic: A guide on how to make a multiplayer game
ThanksHow to make a multiplayer game
To understand multiplayer games, lets talk about what cloud data is, more importantly a cloud variable, simply put its a variable that holds numbers, with a max length of 10240 characters, these characters can only be numbers, you cannot put letters in a cloud variable, cloud variables are variables that can be edited by any scratcher and they appear almost instantly on the other side on the golobe, also there is no official "Cloud lists yet, So how do we fix this? We use a cloud list engine, simply put, a cloud list engie encodes data (Words, things, whatever etc.) into numbers, so we can store it on the cloud variable, and then we have the option to put it back the way it was, also known as decoding the data.How a cloud list engine works and how to use it
As i explained above, a cloud list engine works by encoding and decoding letters, numbers, or data you give it, you might not think that using a cloud list engine is necessary, but believe me it is :) This will allow us to keep track of their usernames, so you can see who you are playing with :). The engine i use has to main custom blocks, they areSave [List... v] to [Variable... v] :: motion
Load () to [List... v] :: motion
The Save block saves a list to the cloud, lets say you have a list with peoples name, and everytime someone clicked the flag, their name would be added, we would first load the list, which puts whatever is in the cloud to as it was before it was saved, so we have the latest data, then we would add the username to the list, and hen we would save it, it would look like thiswhen green flag clicked
if <not <[Usernames v] contains (username)>> then
Load (☁ Users) to [Usernames v] :: custom
add (username) to [Usernames v]
Save [Username v] to [☁ Users v] ::custom
end
this script will check if the list does not contain your username, to avoid username spam, then it would load the data to a list i created called “Username” from the cloud variable “Users” it would add username to the list usernames, and save username to the cloud variable called “Users”, this is not found in your scratch inventory for those of you frantically searching, simply add the sprite located in this project to your backpack
https://scratch-mit-edu.ezproxyberklee.flo.org/projects/68788730/
Notice!
If you dont understand this, feel free to ask in the comments, id be happy to explain in more detail how a cloud list engine worksMultiplayer Game Setup
Lets setup your game, before we begin anything, lets make an average menu that has a button that says join, the join button should be one sprite, then make 4 sprites, called “Client” “Player 1” “Player 2” “Player 3” “Player4”, draw your character in the middle of the scratch art editor, be sure to create your first character before creating the other player sprites so you dont have to create the characters again, so basically just duplicate it three other times once you are finished with the first sprite, lets make a sprite called “Multiplayer” and the final sprite should be the one we just got called “Cloud list engine”, before continuing on to the first step, make sure that your menu works, and put when flag clicked, hide in all player sprites,make sure the button “Join” broadcasts “Join” and hides itself once clicked, but shows itself when the * is clicked, basic stuffThe Multiplayer Game
What this script will do is kick inactive players, start an inactive forever player checker (Checks that players are actually online), and find the ID of the player (This is so we know which player you are) based on who is online. Lets start with the activity checker, basically the client (You) will have a script which changes its check by one, we will have a list containing four items with 0, this list will be called(Checker :: list)This is where what we learned about cloud lists comes in handy, the activity reporter (Tells the project that you are alive) must look like thisOn Client SpriteThis will basically replace the last item of your four item profile with the previous item plus 1, so the program knows if you are alive, but this needs to be put on dat cloud :P Here is how to do so, this does not broadcast anything to the cloud, the script that will will be on the moving (Plataformer) script, dat script is huge :Pwhen I receive [IdRec v]
forever
if <(ID) = [1 ]> then
replace item (4 v) of [Player1 v] with ((item (3 v) of [Player1 v]) + (1))
end
if <(ID) = [2]> then
replace item (4 v) of [Player2 v] with ((item (3 v) of [Player2 v]) + (1))
end
if <(ID) = [3]> then
replace item (4 v) of [Player3 v] with ((item (3 v) of [Player3 v]) + (1))
end
if <(ID) = [4]> then
replace item (4 v) of [Player3 v] with ((item (3 v) of [Player4 v]) + (1))
end
endOn CloudList engine spriteCool! This does not do anything yet but it will soon :O Now lets head on over to the empty multiplayer sprite, This will check if people are alive,not report it, so this can be done by doing this, we will need only two scripts here and you never have to touch this again :D (On this sprite only)when I receive [LoadChecker v]
if <(ID)=[1]> then
Load (☁ Player2) to [Player2 v] :: custom
Load (☁ Player3) to [Player3 v] :: custom
Load (☁ Player4) to [Player4 v] :: custom
else
if <(ID)=[2]> then
Load (☁ Player1) to [Player1 v] :: custom
Load (☁ Player3) to [Player3 v] :: custom
Load (☁ Player4) to [Player4 v] :: custom
else
if <(ID)=[3]> then
Load (☁ Player1) to [Player1 v] :: custom
Load (☁ Player2) to [Player2 v] :: custom
Load (☁ Player4) to [Player4 v] :: custom
else
if <(ID)=[4]> then
Load (☁ Player1) to [Player1 v] :: custom
Load (☁ Player2) to [Player2 v] :: custom
Load (☁ Player3) to [Player3 v] :: custom
when I receive [SaveChecker v]
if <(ID)=[1]
Save [Player1 v] to [☁ Player1 v] :: custom
else
if <(ID)=[2]
Save [Player2 v] to [☁ Player2 v] :: custom
else
if <(ID)=[3]
Save [Player3 v] to [☁ Player3 v] :: custom
else
if <(ID)=[4]
Save [Player4 v] to [☁ Player4 v] :: custom
and will make sure that new players dont join unless their is space available for themThe Multiplayer SpriteWe are almost done! Nah im messing with you, but we are doing good :P Now for the client, add this script to your client sprite (A platformer script is what makes your character move, a greaaaaaat platformer script can be found here: https://scratch-mit-edu.ezproxyberklee.flo.org/projects/34429446/, now lets consider the plataformer script is all in a block, called plataform (Simply because I do not want to type a very long script right now, take out the forever loop in the plataform script and put it in with a new one, and then we will add a tiny script below the plataformer script that will check the ID of the users and add the x and y positions to their profilewhen I receive [Join v]
delete (all v) of [.Check v]
add (☁ Player1) to [.Check v]
add (☁ Player2) to [.Check v]
add (☁ Player3) to [.Check v]
add (☁ Player4) to [.Check v]
wait (2) secs
if < not <(☁ Player4) = (item (4 v) of [.check v])>>
if <(☁ Player1) = (item (1 v) of [.check v])> then
set [ID v] to [ 1]
else
if <(☁ Player2) = (item (2 v) of [.check v])> then
set [ID v] to [ 2]
else
if <(☁ Player3) = (item (3 v) of [.check v])> then
set [ID v] to [ 3]
else
if <(☁ Player4) = (item (4 v) of [.check v])> then
set [ID v] to [ 4]
end
end
end
end
broadcast [IdRec v]
when I receive [IdRec v]
delete (all v) of [Inactive v]
forever
delete (all v) of [.Check v]
add (☁ Player1) to [.Check v]
add (☁ Player2) to [.Check v]
add (☁ Player3) to [.Check v]
add (☁ Player4) to [.Check v]
wait (2) secs
if <(☁ Player1) = (item (1 v) of [.check v])> then
set [ID v] to [ 1]
else
add [1] to [ Inactive v]
if <(☁ Player2) = (item (2 v) of [.check v])> then
set [ID v] to [ 2]
else
add [2] to [ Inactive v]
if <(☁ Player3) = (item (3 v) of [.check v])> then]
set [ID v] to [ 3]
else
add [3] to [ Inactive v]
if <(☁ Player4) = (item (4 v) of [.check v])> then
set [ID v] to [ 4]
else
add [4] to [ Inactive v]
end
end
endThe Client Spriteif you got through that then congratz, now if not done already build a platform where your players will be on, just a flat one, and now we are almost done, not joking this time, now there is one script you have to add to all players sprites, for example the scripts will use the last letter of the players sprite, so for example this would be the script in the first player spritewhen I receive [IdRec v]
forever
"PlataformerScriptOfYourChoice" :: pen
if <(ID) =[1]> then
replace item [1] of [Player1 v] with (x position)
replace item [2] of [Player1 v] with (y position)
replace item [3] of [Player1 v] with (Username)
else
if <(ID) =[2]> then
replace item [1] of [Player2 v] with (x position)
replace item [2] of [Player2 v] with (y position)
replace item [3] of [Player2 v] with (Username)
else
if <(ID) =[3]> then
replace item [1] of [Player3 v] with (x position)
replace item [2] of [Player3 v] with (y position)
replace item [3] of [Player3 v] with (Username)
else
if <(ID) =[4]> then
replace item [1] of [Player4 v] with (x position)
replace item [2] of [Player4 v] with (y position)
replace item [3] of [Player4 v] with (Username)
end
end
end
end
broadcast [SaveChecker v] and waitand for player two, replace the not id = 1 to not Id = 2 and not inactive contains one to not inactive contains 2 and replace all the player one lists two player 2 lists, if you did this successfully you have th simplest script weve ever made and were finished for real, add this where ever you want, preferabbly in the multplayer sprite, it has to saywhen green flag clicked
forever
if <not <(ID) = [ 1]>> then
if <not <[Inactive v] contains [1]>> then
show
go to x: (item (1 v) of [Player1 v]) y: (item (2 v) of [Player1 v])
say (item (3 v) of [Player1 v])
else
hide
end
endand theyre you go! you have a fully working multiplayer project, tell me in the comments if you are having trouble so i can help :)when I receive [Join v]
forever
broadcast [LoadChecker v] and wait
end
Good day!~EncloCreations
- awesome-llama
-
1000+ posts
ITopic: A guide on how to make a multiplayer game
You can use the scratchblocks tag to make any block you want why did you use hacked blocks
- xXScratch__MasterXx
-
5 posts
ITopic: A guide on how to make a multiplayer game
How to make a multiplayer game
To understand multiplayer games, lets talk about what cloud data is, more importantly a cloud variable, simply put its a variable that holds numbers, with a max length of 10240 characters, these characters can only be numbers, you cannot put letters in a cloud variable, cloud variables are variables that can be edited by any scratcher and they appear almost instantly on the other side on the golobe, also there is no official "Cloud lists yet, So how do we fix this? We use a cloud list engine, simply put, a cloud list engie encodes data (Words, things, whatever etc.) into numbers, so we can store it on the cloud variable, and then we have the option to put it back the way it was, also known as decoding the data.How a cloud list engine works and how to use it
As i explained above, a cloud list engine works by encoding and decoding letters, numbers, or data you give it, you might not think that using a cloud list engine is necessary, but believe me it is :) This will allow us to keep track of their usernames, so you can see who you are playing with :). The engine i use has to main custom blocks, they areSave [List... v] to [Variable... v] :: motion
Load () to [List... v] :: motion
The Save block saves a list to the cloud, lets say you have a list with peoples name, and everytime someone clicked the flag, their name would be added, we would first load the list, which puts whatever is in the cloud to as it was before it was saved, so we have the latest data, then we would add the username to the list, and hen we would save it, it would look like thiswhen green flag clicked
if <not <[Usernames v] contains (username)>> then
Load (☁ Users) to [Usernames v] :: custom
add (username) to [Usernames v]
Save [Username v] to [☁ Users v] ::custom
end
this script will check if the list does not contain your username, to avoid username spam, then it would load the data to a list i created called “Username” from the cloud variable “Users” it would add username to the list usernames, and save username to the cloud variable called “Users”, this is not found in your scratch inventory for those of you frantically searching, simply add the sprite located in this project to your backpack
https://scratch-mit-edu.ezproxyberklee.flo.org/projects/68788730/
Notice!
If you dont understand this, feel free to ask in the comments, id be happy to explain in more detail how a cloud list engine worksMultiplayer Game Setup
Lets setup your game, before we begin anything, lets make an average menu that has a button that says join, the join button should be one sprite, then make 4 sprites, called “Client” “Player 1” “Player 2” “Player 3” “Player4”, draw your character in the middle of the scratch art editor, be sure to create your first character before creating the other player sprites so you dont have to create the characters again, so basically just duplicate it three other times once you are finished with the first sprite, lets make a sprite called “Multiplayer” and the final sprite should be the one we just got called “Cloud list engine”, before continuing on to the first step, make sure that your menu works, and put when flag clicked, hide in all player sprites,make sure the button “Join” broadcasts “Join” and hides itself once clicked, but shows itself when the * is clicked, basic stuffThe Multiplayer Game
What this script will do is kick inactive players, start an inactive forever player checker (Checks that players are actually online), and find the ID of the player (This is so we know which player you are) based on who is online. Lets start with the activity checker, basically the client (You) will have a script which changes its check by one, we will have a list containing four items with 0, this list will be called(Checker :: list)This is where what we learned about cloud lists comes in handy, the activity reporter (Tells the project that you are alive) must look like thisOn Client SpriteThis will basically replace the last item of your four item profile with the previous item plus 1, so the program knows if you are alive, but this needs to be put on dat cloud :P Here is how to do so, this does not broadcast anything to the cloud, the script that will will be on the moving (Plataformer) script, dat script is huge :Pwhen I receive [IdRec v]
forever
if <(ID) = [1 ]> then
replace item (4 v) of [Player1 v] with ((item (3 v) of [Player1 v]) + (1))
end
if <(ID) = [2]> then
replace item (4 v) of [Player2 v] with ((item (3 v) of [Player2 v]) + (1))
end
if <(ID) = [3]> then
replace item (4 v) of [Player3 v] with ((item (3 v) of [Player3 v]) + (1))
end
if <(ID) = [4]> then
replace item (4 v) of [Player3 v] with ((item (3 v) of [Player4 v]) + (1))
end
endOn CloudList engine spriteCool! This does not do anything yet but it will soon :O Now lets head on over to the empty multiplayer sprite, This will check if people are alive,not report it, so this can be done by doing this, we will need only two scripts here and you never have to touch this again :D (On this sprite only)when I receive [LoadChecker v]
if <(ID)=[1]> then
Load (☁ Player2) to [Player2 v] :: custom
Load (☁ Player3) to [Player3 v] :: custom
Load (☁ Player4) to [Player4 v] :: custom
else
if <(ID)=[2]> then
Load (☁ Player1) to [Player1 v] :: custom
Load (☁ Player3) to [Player3 v] :: custom
Load (☁ Player4) to [Player4 v] :: custom
else
if <(ID)=[3]> then
Load (☁ Player1) to [Player1 v] :: custom
Load (☁ Player2) to [Player2 v] :: custom
Load (☁ Player4) to [Player4 v] :: custom
else
if <(ID)=[4]> then
Load (☁ Player1) to [Player1 v] :: custom
Load (☁ Player2) to [Player2 v] :: custom
Load (☁ Player3) to [Player3 v] :: custom
when I receive [SaveChecker v]
if <(ID)=[1]
Save [Player1 v] to [☁ Player1 v] :: custom
else
if <(ID)=[2]
Save [Player2 v] to [☁ Player2 v] :: custom
else
if <(ID)=[3]
Save [Player3 v] to [☁ Player3 v] :: custom
else
if <(ID)=[4]
Save [Player4 v] to [☁ Player4 v] :: custom
and will make sure that new players dont join unless their is space available for themThe Multiplayer SpriteWe are almost done! Nah im messing with you, but we are doing good :P Now for the client, add this script to your client sprite (A platformer script is what makes your character move, a greaaaaaat platformer script can be found here: https://scratch-mit-edu.ezproxyberklee.flo.org/projects/34429446/, now lets consider the plataformer script is all in a block, called plataform (Simply because I do not want to type a very long script right now, take out the forever loop in the plataform script and put it in with a new one, and then we will add a tiny script below the plataformer script that will check the ID of the users and add the x and y positions to their profilewhen I receive [Join v]
delete (all v) of [.Check v]
add (☁ Player1) to [.Check v]
add (☁ Player2) to [.Check v]
add (☁ Player3) to [.Check v]
add (☁ Player4) to [.Check v]
wait (2) secs
if < not <(☁ Player4) = (item (4 v) of [.check v])>>
if <(☁ Player1) = (item (1 v) of [.check v])> then
set [ID v] to [ 1]
else
if <(☁ Player2) = (item (2 v) of [.check v])> then
set [ID v] to [ 2]
else
if <(☁ Player3) = (item (3 v) of [.check v])> then
set [ID v] to [ 3]
else
if <(☁ Player4) = (item (4 v) of [.check v])> then
set [ID v] to [ 4]
end
end
end
end
broadcast [IdRec v]
when I receive [IdRec v]
delete (all v) of [Inactive v]
forever
delete (all v) of [.Check v]
add (☁ Player1) to [.Check v]
add (☁ Player2) to [.Check v]
add (☁ Player3) to [.Check v]
add (☁ Player4) to [.Check v]
wait (2) secs
if <(☁ Player1) = (item (1 v) of [.check v])> then
set [ID v] to [ 1]
else
add [1] to [ Inactive v]
if <(☁ Player2) = (item (2 v) of [.check v])> then
set [ID v] to [ 2]
else
add [2] to [ Inactive v]
if <(☁ Player3) = (item (3 v) of [.check v])> then]
set [ID v] to [ 3]
else
add [3] to [ Inactive v]
if <(☁ Player4) = (item (4 v) of [.check v])> then
set [ID v] to [ 4]
else
add [4] to [ Inactive v]
end
end
endThe Client Spriteif you got through that then congratz, now if not done already build a platform where your players will be on, just a flat one, and now we are almost done, not joking this time, now there is one script you have to add to all players sprites, for example the scripts will use the last letter of the players sprite, so for example this would be the script in the first player spritewhen I receive [IdRec v]
forever
"PlataformerScriptOfYourChoice" :: pen
if <(ID) =[1]> then
replace item [1] of [Player1 v] with (x position)
replace item [2] of [Player1 v] with (y position)
replace item [3] of [Player1 v] with (Username)
else
if <(ID) =[2]> then
replace item [1] of [Player2 v] with (x position)
replace item [2] of [Player2 v] with (y position)
replace item [3] of [Player2 v] with (Username)
else
if <(ID) =[3]> then
replace item [1] of [Player3 v] with (x position)
replace item [2] of [Player3 v] with (y position)
replace item [3] of [Player3 v] with (Username)
else
if <(ID) =[4]> then
replace item [1] of [Player4 v] with (x position)
replace item [2] of [Player4 v] with (y position)
replace item [3] of [Player4 v] with (Username)
end
end
end
end
broadcast [SaveChecker v] and waitand for player two, replace the not id = 1 to not Id = 2 and not inactive contains one to not inactive contains 2 and replace all the player one lists two player 2 lists, if you did this successfully you have th simplest script weve ever made and were finished for real, add this where ever you want, preferabbly in the multplayer sprite, it has to saywhen green flag clicked
forever
if <not <(ID) = [ 1]>> then
if <not <[Inactive v] contains [1]>> then
show
go to x: (item (1 v) of [Player1 v]) y: (item (2 v) of [Player1 v])
say (item (3 v) of [Player1 v])
else
hide
end
endand theyre you go! you have a fully working multiplayer project, tell me in the comments if you are having trouble so i can help :)when I receive [Join v]
forever
broadcast [LoadChecker v] and wait
end
Good day!~EncloCreations
I created a project but it doesn't work. can you see why?
https://scratch-mit-edu.ezproxyberklee.flo.org/projects/92447158/#editor
- Mr_Bob_57
-
3 posts
ITopic: A guide on how to make a multiplayer game
Notice!
If you dont understand this, feel free to ask in the comments, id be happy to explain in more detail how a cloud list engine works
Umm how should I define the cloud engine custom blocks?
Yeah i had trouble with that to!


Last edited by Mr_Bob_57 (Dec. 28, 2015 18:05:13)
- iArmorStand
-
17 posts
ITopic: A guide on how to make a multiplayer game
1.When do the players appear
2.The platformer game link doesn't work
2.The platformer game link doesn't work
when I receive [Hugs v]
stop [time v]
turn back in time
broadcast [fake death v] and wait
stop [living in the city v]
move (to china and trip on) steps
set [status v] to [presumed dead ]
- iArmorStand
-
17 posts
ITopic: A guide on how to make a multiplayer game
didn't work for me #didn'twork
https://scratch-mit-edu.ezproxyberklee.flo.org/projects/92771658/
https://scratch-mit-edu.ezproxyberklee.flo.org/projects/92771658/
- Discussion Forums
- » Help with Scripts
-
» ITopic: A guide on how to make a multiplayer game