Discuss Scratch

shadow4689
Scratcher
6 posts

how do you make a multiplayer game script?

I had an idea and I said yeah that would be great with multiplayer but I didn't know how at make a multiplayer script so could you help me?
eliperr
Scratcher
89 posts

how do you make a multiplayer game script?

When you say multiplayer I assume you mean online player, meaning players on different computers can play together.
You will need to use cloud variables for this. When a player presses a key you will need to check which player is doing so and change a cloud variable. Like when player1 presses the right key:
ifplayer= 1thenifkey rightpressed?thenchange☁player1Xby1

the cloud variable player1x will increase (as x positions do when going to the right) which corresponds to the x position of player1's sprite or clone of a sprite.




There's a bit more and it is a little complicated so I will refer you to this helpful tutorial. If you have any questions I can explain it to you.

Last edited by eliperr (Dec. 27, 2015 06:17:42)

shadow4689
Scratcher
6 posts

how do you make a multiplayer game script?

thanks that really helps!!!
KermitMC
Scratcher
100+ posts

how do you make a multiplayer game script?

If you just want a script for a couple of players that can move around. You'll only need 1 cloud variable.
You take the x pos and y pos of each person and add 400. Then you join them together and put them in a cloud variable. I'd also suggest multiplying the joint number by 10 so you can check if that user is still online by adding 1, 9 times then resetting it to 0 once it reaches 10.

To check for a free spot you'll check this changing number at the end of each joint number to see if it's changing, if it's not changing, join the player to that spot and start changing the variable. Once they leave, the variable will stop changing and a new user can join that spot. It is very easy to get this data from the large string of numbers in the cloud variable because each string for each player will be 7 “letters” long. 3 for the x position, 3 for the y position and 1 for the online checker.

You make 2 sprites. 1 sprite will be for the player who is playing from their PC, the other sprite will display all other players using clones or stamps if there is no other user input.

I do not recommend using more than 1 cloud variable to store current user data as that will only allow for a limited amount of things you can do. If you start using 1 variable from the beginning you'll never have to use more than 1 cloud variable. Unless you need to store individual player data when they exit. This will be long-term data and is different to current data. Current data is only needed while the user is playing and can be written over once a new player comes to play. Long-term data should be stored separately as you do not want it written over, it is used to store the users progress and the next time they enter the project, they should get their data from the last time they played.

Powered by DjangoBB