Discuss Scratch

EncloCreations
Scratcher
500+ posts

ITopic: A guide on 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 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

Last edited by EncloCreations (Nov. 2, 2016 17:18:08)

ZozaTech
Scratcher
500+ posts

ITopic: A guide on how to make a multiplayer game

Hi. It is nice you like to help others! But the help with scripts is only for helping other people with their problems
Thanks though

Loading signature….. ▓▓▓▓▓▓▓▓▓▓▓ 100%
If you are a fan of me, feel free to join THIS

Click here to see how to get lots of followers!
Do you like my post? url=http://internetometer.com/give/45365]Give me an internet by clicking here!
Last edited by Kaj (Dec. 9, 2015 16:09:41)
EncloCreations
Scratcher
500+ posts

ITopic: A guide on how to make a multiplayer game

ZozaTech wrote:

Hi. It is nice you like to help others! But the help with scripts is only for helping other people with their problems
Thanks though
Oh okey, thankyou i was confused
deck26
Scratcher
1000+ posts

ITopic: A guide on how to make a multiplayer game

EncloCreations wrote:

ZozaTech wrote:

Hi. It is nice you like to help others! But the help with scripts is only for helping other people with their problems
Thanks though
Oh okey, thankyou i was confused
I agree with @ZozaTech. Otherwise we end up with so many posts like this fighting to remain on or near the first page that there's no room for people to actually ask for help. There are dozens of topics that could be covered in this way.

I haven't checked the detail of your post but if you want to do something like that I would recommend making a project that covers the topic. If its good enough it will get referred to by people helping here.
EncloCreations
Scratcher
500+ posts

ITopic: A guide on how to make a multiplayer game

Actually it says you are allowed to post guides here
Thats what a lot of people do
deck26
Scratcher
1000+ posts

ITopic: A guide on how to make a multiplayer game

EncloCreations wrote:

Actually it says you are allowed to post guides here
Thats what a lot of people do
You are allowed to but they'll quickly get lost as new posts come in unless you keep bumping them. In my opinion it's much better to leave as much of the first few pages as possible for people asking for help - in which case posts like yours are likely to be overlooked and only have limited impact. That was my point.
EncloCreations
Scratcher
500+ posts

ITopic: A guide on how to make a multiplayer game

bump
deck26
Scratcher
1000+ posts

ITopic: A guide on how to make a multiplayer game

EncloCreations wrote:

bump
and that's the problem. You want people to see your post so you keep bumping it. Other people write guides and do the same. Other people create posts that essentially replicate the forum. So the poor Scratcher who wants to ask a question finds their request quickly drops down and is easily overlooked because people can't be bothered going beyond the first page or two.

I'd be all in favour of a separate forum for guides etc but do not feel they really fit well here.
EncloCreations
Scratcher
500+ posts

ITopic: A guide on how to make a multiplayer game

i can bump it if i want to,
deck26
Scratcher
1000+ posts

ITopic: A guide on how to make a multiplayer game

EncloCreations wrote:

i can bump it if i want to,
Of course you can. It's about consideration for others though.
EncloCreations
Scratcher
500+ posts

ITopic: A guide on how to make a multiplayer game

Whut, lol im joking xD But seriously, its part of this thread
makethebrainhappy
Scratcher
1000+ posts

ITopic: A guide on how to make a multiplayer game

EncloCreations wrote:

Whut, lol im joking xD But seriously, its part of this thread

Actually I like the guide. I could post it as a tutorial in my shop ….

Also I want to speak to you XD
makethebrainhappy
Scratcher
1000+ 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?
EnderScout_77
Scratcher
100+ posts

ITopic: A guide on how to make a multiplayer game

This is a GREAT tutorial. So, um, how do you report topics to be stickied? (You know what I mean )
EncloCreations
Scratcher
500+ posts

ITopic: A guide on how to make a multiplayer game

Hey makethebrainhappy! So step 1, go to the link i provided, https://scratch.mit.edu/projects/68788730/, secondly, put the sprite that says cloud list engine on your backpack, now got to any project of yours and drag the sprite onto your project, fourth go to custom blocks, and the two blocks shown should appeard, they are already defined for you, hope this helps
EncloCreations
Scratcher
500+ posts

ITopic: A guide on how to make a multiplayer game

EnderScout_77 wrote:

This is a GREAT tutorial. So, um, how do you report topics to be stickied? (You know what I mean )
Hey thanks man, to report a topic click report and then the reason (Type you want it to be stickied)
ethan-4518
Scratcher
19 posts

ITopic: A guide on how to make a multiplayer game

thanks!
kieranblackley
Scratcher
500+ posts

ITopic: A guide on how to make a multiplayer game

why did you use hacked blocks

Bored? Want to see something great? Check out my profile today!
EncloCreations
Scratcher
500+ posts

ITopic: A guide on how to make a multiplayer game

Its not a hack, its a trick
LamKaJ
Scratcher
7 posts

ITopic: A guide on how to make a multiplayer game

when green flag clicked

Powered by DjangoBB

Standard | Mobile