How to Make Multiplayer Games In Scratch? Step-by-Step Game Tutorial
- Aditi |
- August 23, 2024
Updated By
Reviewed By
Multiplayer games in Scratch are the types of games that are played by many players at the same time. Multiplayer games can be played on the same system (computer) or different systems with players being at different places.
If a multiplayer game is being played on the same system by all the players, then it is known as “Local Multiplayer” and if a multiplayer game is being played on different systems by different players being at different places, then it is known as an “Online Multiplayer” and is done through the use of cloud data and cloud variables.
Cloud variables are the variables that are stored on the cloud server and once changed, update the changes in all the copies of the project and save them for further usage. These variables have a small cloud icon next to their names and are necessary for the creation of online multiplayer games. However, due to certain restrictions on cloud variables, new scratchers are not authorized to create cloud variables. You need to be using Scratch for a pretty long time in order to develop cloud variables.
Looking to learn Scratch coding? Explore Wiingy’s Online Scratch Coding Classes For Kids to learn from top Scratch coding experts.
How to create local multiplayer games in Scratch?
Local Multiplayer Games are games that are played on the same system by many players at the same time and place. Cloud variables are not required for the creation of local multiplayer games.
In local multiplayer games, there are two scripts, one script is created for the first player, and another script is created for the second player. The scripts created for the players in the local multiplayer games can be created as per the requirement of the project. Usually, one player controls the left side of the keyboard, that is, W, A, S, D, and F keys and another player controls the right side of the keyboard, that is, the number keys and the arrow keys. This way the game becomes easier for the users to play.
The following scripts are an example of a local multiplayer game, so just follow the given steps:
Create a script for the first player:
- Step 1: Go to the “Events” block on the block palette, select the “when (green flag) clicked” block, and drag to the coding area.
- Step 2: Go to the “Control” block on the block palette, select the “forever ( )” block, drag to the coding area, and place it under the “when (green flag) clicked” block.
- Step 3: From the “Control” block on the block palette, select the “if ( ) then” block, drag to the coding area, and place it inside the “forever ( )” block.
- Step 4: Go to the “Sensing” block on the block palette, select the “key ( ) pressed?” block, drag to the coding area, and place it in the ‘if condition’ of the “if ( ) then” block.
- Step 5: In the “key ( ) pressed?” block, select the “left arrow” option from the drop-down menu.
- Step 6: Go to the “Motion” block on the block palette, select the “move ( ) steps” block, drag to the coding area, and place it in the then condition of the “if ( ) then” block.
- Step 7: In the “move ( ) steps” block, enter the steps as “-10”.
- Step 8: From the “Control” block on the block palette, again select the “if ( ) then” block, drag to the coding area, and place it under the first “if ( ) then” block and inside the “forever ( )” block.
- Step 9: From the “Sensing” block on the block palette, again select the “key ( ) pressed?” block, drag it to the coding area and place it in the ‘if condition’ of the second “if ( ) then” block.
- Step 10: In the “key ( ) pressed?” block, select the “right arrow” option from the drop-down menu.
- Step 11: From the “Motion” block on the block palette, again select the “move ( ) steps” block, drag it to the coding area, and place it in the then condition of the second “if ( ) then” block. In the “move ( ) steps” block, the steps count is “10”, by default, so leave it like that.
- Step 12: Your final script for the first player will look as shown below.
Create a script for the second player:
- Step 1: Go to the “Events” block on the block palette, select the “when (green flag) clicked” block, and drag to the coding area.
- Step 2: Go to the “Control” block on the block palette, select the “forever ( )” block, drag to the coding area, and place it under the “when (green flag) clicked” block.
- Step 3: From the “Control” block on the block palette, select the “if ( ) then” block, drag to the coding area, and place it inside the “forever ( )” block.
- Step 4: Go to the “Sensing” block on the block palette, select the “key ( ) pressed?” block, drag to the coding area, and place it in the ‘if condition’ of the “if ( ) then” block.
- Step 5: In the “key ( ) pressed?” block, select the “a” option from the drop-down menu.
- Step 6: Go to the “Motion” block on the block palette, select the “move ( ) steps” block, drag to the coding area, and place it in the then condition of the “if ( ) then” block.
- Step 7: In the “move ( ) steps” block, enter the steps as “-10”.
- Step 8: From the “Control” block, again select the “if ( ) then” block, drag to the coding area, and place it under the first “if ( ) then” block and inside the “forever ( )” block. Then, from the “Sensing” block on the block palette, again select the “key ( ) pressed?” block, drag it to the coding area, and place it in the if condition of the second “if ( ) then” block.
- Step 9: In the “key ( ) pressed?” block, select the “d” option from the drop-down menu.
- Step 10: From the “Motion” block on the block palette, again select the “move ( ) steps” block, drag it to the coding area, and place it in the then condition of the second “if ( ) then” block. In the “move ( ) steps” block, the steps count is “10”, by default, so leave it like that.
- Step 11: Your final script for the first player will look as shown below.
Online multiplayer games
Online Multiplayer Games are games that are played on different systems by different players at the same time but from different places. Cloud variables are required for the creation of online multiplayer games and only old scratchers are authorized to create cloud variables and hence online multiplayer games.
In online multiplayer games, the user first needs to create some cloud variables to detect the player’s movements and check if any of the players are still active or not. Since online multiplayer games are played online by the players using the cloud variables, so one script is created to check if any slot is available so that other players can also join the game.
Now, two scripts will be created, one script is created for the first player, and another script is created for the second player. The conditions in the scripts created for the players in the online multiplayer games can be created per the project’s requirement. One more script will be created for informing the players about any kinds of errors such as errors connecting to the game, etc. because the game will be played online using the internet connection.
In this way, by creating all the scripts mentioned above, a perfectly working online multiplayer game can be created.
Looking to learn Scratch coding? Explore Wiingy’s Online Scratch Coding Classes For Kids to learn from top Scratch coding experts.
Frequently asked questions (FAQs)
What is a multiplayer game?
A multiplayer game is a game that is played by many players at the same time. Multiplayer games can be played on the same system (computer) or different systems with players being at different places.
What are the types of multiplayer games?
There are two types of multiplayer games, local multiplayer games, and online multiplayer games.
What are cloud variables in Scratch?
In Scratch, cloud variables are the variables that are stored on the cloud server, and once changed, update the changes in all the copies of the project and save them for further usage.
What are the local multiplayer games?
Local Multiplayer Games are games that are played on the same system by many players at the same time and place.
Can new scratchers create cloud variables in Scratch?
No, new scratchers can’t create cloud variables in Scratch. Due to certain restrictions, only old scratchers are authorized to create cloud variables.
We hope you understand what multiplayer games are and how to create multiplayer games in Scratch. If you have any doubts, you can ask your doubts in the comment section. If you want to continue your Scratch learning journey, read our blog on 10 Scratch games to create and play!