Discuss Scratch

WolfCat67
Scratcher
1000+ posts

ITopic: A guide on how to make a multiplayer game

This is a good guide; however, keep in mind that all the “if” statements will appear as red unless you put “then” after the Boolean inputs on Scratch.
If you fix those, then it'll be perfect!
jromagnoli
Scratcher
1000+ posts

ITopic: A guide on how to make a multiplayer game

I have a question. Should the lists, player1, player2, player3, and player4 be cloud lists? Thanks.
keeganfk
Scratcher
14 posts

ITopic: A guide on how to make a multiplayer game

jromagnoli wrote:

I have a question. Should the lists, player1, player2, player3, and player4 be cloud lists? Thanks.
Cool platformers
ComputerGames4U
Scratcher
100+ posts

ITopic: A guide on how to make a multiplayer game

About that how do I make the blocks. I have an answer!

Last edited by ComputerGames4U (Jan. 19, 2017 21:45:14)

bakerboys
Scratcher
37 posts

ITopic: A guide on how to make a multiplayer game

ComputerGames4U wrote:

About that how do I make the blocks.

how?
ComputerGames4U
Scratcher
100+ posts

ITopic: A guide on how to make a multiplayer game

My sprite can't move because of the script.
ComputerGames4U
Scratcher
100+ posts

ITopic: A guide on how to make a multiplayer game

bakerboys wrote:

ComputerGames4U wrote:

About that how do I make the blocks.

how?

If you go to the project put the define script of the block and copy it or just put it in your backpack!
bakerboys
Scratcher
37 posts

ITopic: A guide on how to make a multiplayer game

thanks
Diesel1997
Scratcher
7 posts

ITopic: A guide on how to make a multiplayer game

Ty For Helping me Its Help Ful
banana552
Scratcher
5 posts

ITopic: A guide on how to make a multiplayer game

I'm making a fighting game and I want it so u can battle with friends over the web the only stat is health and it relies on costumes
for example a monster switches to a “doing an attack skin” then the other will wait until the fireball sprite hits the other side of the screen then the enemy will lose health do u know how to code a multiplayer version
country_kid
Scratcher
100+ posts

ITopic: A guide on how to make a multiplayer game

EncloCreations wrote:


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 are
Save [List... v] to [Variable... v] :: custom

Load () to [List... v] :: custom

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 this

when green flag clicked
Load (☁ Users) to [Usernames v] :: custom
if <not <[Usernames v] contains (username)>> then
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/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 works

Multiplayer 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 stuff

The 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 this
On Client Sprite
when 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 [Player4 v] with ((item (3 v) of [Player4 v]) + (1))
end

end
This 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 :P
On CloudList engine sprite
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
Cool! 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)
and will make sure that new players dont join unless their is space available for them

The Multiplayer Sprite
when 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
end
We 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/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 profile
The Client Sprite
when 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 wait
if 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 sprite
when 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

end
and 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 say
when I receive [Join v]
forever

broadcast [LoadChecker v] and wait
end
and theyre you go! you have a fully working multiplayer project, tell me in the comments if you are having trouble so i can help :)
Good day!
Notice:
Chat rooms are not allowed in scratch, yet! So please avoid making a chat unless its a safe chat, which is quite complicated to do ;)
~EncloCreations


I made a cloud tutorial series on this, its really long but explains it really well (You can skip ahead of the videos if you want to just for the good stuff but be careful because i cover some important concepts) : https://www.youtube.com/channel/UCkPYZZ5k0axY170MaUVLKiQ
make it easy
ninja-viking
Scratcher
16 posts

ITopic: A guide on how to make a multiplayer game

EncloCreations wrote:


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 are
Save [List... v] to [Variable... v] :: custom

Load () to [List... v] :: custom

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 this

when green flag clicked
Load (☁ Users) to [Usernames v] :: custom
if <not <[Usernames v] contains (username)>> then
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/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 works

Multiplayer 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 stuff

The 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 this
On Client Sprite
when 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 [Player4 v] with ((item (3 v) of [Player4 v]) + (1))
end

end
This 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 :P
On CloudList engine sprite
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
Cool! 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)
and will make sure that new players dont join unless their is space available for them

The Multiplayer Sprite
when 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
end
We 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/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 profile
The Client Sprite
when 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 wait
if 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 sprite
when 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

end
and 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 say
when I receive [Join v]
forever

broadcast [LoadChecker v] and wait
end
and theyre you go! you have a fully working multiplayer project, tell me in the comments if you are having trouble so i can help :)
Good day!
Notice:
Chat rooms are not allowed in scratch, yet! So please avoid making a chat unless its a safe chat, which is quite complicated to do ;)
~EncloCreations


I made a cloud tutorial series on this, its really long but explains it really well (You can skip ahead of the videos if you want to just for the good stuff but be careful because i cover some important concepts) : https://www.youtube.com/channel/UCkPYZZ5k0axY170MaUVLKiQ









how are you meant to define the custom blocks?
EncloCreations
Scratcher
500+ posts

ITopic: A guide on how to make a multiplayer game

This tutorial is currently broken because of the new cloud. Infact most multiplayer games are broken, i managed to find a way to make it widespread again but its going to take me some time to make it easy for everyone to understand and follow.
wafflezzzzzz
Scratcher
1 post

ITopic: A guide on how to make a multiplayer game

Where is the save block (or how do you create it)
wetsoggydoggy
Scratcher
22 posts

ITopic: A guide on how to make a multiplayer game

LamKaJ wrote:

when green flag clicked

bro what are you talking about
wetsoggydoggy
Scratcher
22 posts

ITopic: A guide on how to make a multiplayer game

like guys
wetsoggydoggy
Scratcher
22 posts

ITopic: A guide on how to make a multiplayer game

Bold and how to make multiplayer game

:ggygyLin()bjhg


You welcome

Also, understand it
funny-longan
Scratcher
8 posts

ITopic: A guide on how to make a multiplayer game

EncloCreations wrote:


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 are
Save [List... v] to [Variable... v] :: custom

Load () to [List... v] :: custom

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 this

when green flag clicked
Load (☁ Users) to [Usernames v] :: custom
if <not <[Usernames v] contains (username)>> then
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/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 works

Multiplayer 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 stuff

The 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 this
On Client Sprite
when 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 [Player4 v] with ((item (3 v) of [Player4 v]) + (1))
end

end
This 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 :P
On CloudList engine sprite
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
Cool! 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)
and will make sure that new players dont join unless their is space available for them

The Multiplayer Sprite
when 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
end
We 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/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 profile
The Client Sprite
when 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 wait
if 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 sprite
when 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

end
and 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 say
when I receive [Join v]
forever

broadcast [LoadChecker v] and wait
end
and theyre you go! you have a fully working multiplayer project, tell me in the comments if you are having trouble so i can help :)
Good day!
Notice:
Chat rooms are not allowed in scratch, yet! So please avoid making a chat unless its a safe chat, which is quite complicated to do ;)
~EncloCreations


I made a cloud tutorial series on this, its really long but explains it really well (You can skip ahead of the videos if you want to just for the good stuff but be careful because i cover some important concepts) : https://www.youtube.com/channel/UCkPYZZ5k0axY170MaUVLKiQ
Thank you!
beginner_creator123
Scratcher
11 posts

ITopic: A guide on how to make a multiplayer game

move () steps
turn cw () degrees
turn ccw () degrees
turn ccw () degrees
point in direction ( v)
point towards [ v]
go to x: () y: (0)
go to [ v]
go to [ v]
change x by ()
change x by ()
set x to ()
change y by ()
define ()
hide variable [ v]
show variable [ v]
change [ v] by (0)
set [(☁ score) v] to []

Last edited by beginner_creator123 (July 4, 2020 01:22:50)

spidey-x
Scratcher
6 posts

ITopic: A guide on how to make a multiplayer game

so umwhat is the purple block is it an my block or sound

Powered by DjangoBB