What is MMO?
MMO (massively multiplayer online) is a type of video game with a large number of players on the same server. MMO games enable players to cooperate and compete with each other.
Multiplayer mode makes a game more replayable, but in the past it was hard for creators to design an MMO system. You need to build a matchmaking system, a broadcast system, a sync system, and so on.
Why use Simple MMO?
Making an MMO game in Scratch is extremely hard because of the cloud variables. For example:
- A cloud variable doesn't accept strings, so you must encode and decode.
- Usually, you need to share more than one project to build multiple servers for more players.
To simplify the development of MMO games, Gandi IDE built this extension.
Best Practices
Video Guide
Episode 1 - Connection & Message
Episode 2 - Online Players
Episode 3 - Matching System
Modules
Module | Description |
🚥 Connection and Basic Info | - Connect to a room
- Disconnect
- Get the data from a room
- Set and get extra data of the current room
- Changes in a room
- Test |
🗺 Game Lobby | - Get data of match rooms in a lobby |
🎾 Match Game | - Join or create a match room in a lobby
- Lock or unlock a match room |
✉️ Message | - Broadcast a message
- Receive a message |
😽 Player | - Get states of players in the room
- Set the value of states |
🙀 Player Event | - Listen to changes of players in the room.
- Get data on players who changed their states. |
🛠 Utils | - Check if the sprite is a clone. |
Functions and Definitions
🚥 Connection and Basic info
Connect to a room
Connect to an online room with server ID and extra data.
Selection | Description |
How to connect | Select how to connect to a room. There are two options.
- Join or create: Connect to an existing room. If there is no available room. Create a new one.
- Create: Create a new room directly. |
Room type | Select a type of room. There are three options.
- Broadcast: A room for players to join, broadcast messages, and sync states. Each broadcast room has its unique server ID.
- Lobby: The lobby is a collection of match rooms. Players can join a lobby to get information about match rooms sharing the same server ID with the lobby.
- Match room: Match rooms in one lobby share the same server ID. You can set the max player count in a room. |
Property | Description | Example Value |
Server ID | The unique ID of an MMO server. | serverId |
Extra data | Extra data according to the player. You can assign customized values to it. | data |
The following stack block is similar with the first one, but will wait until the player has joined the room successfully.
Disconnect
Use the following stack block to disconnect from a room.
Get the data from a room
This reporter block will return the Internet lag of the current player in the room in ms.
The value of lag is related to the experience of the player.
Value | Description |
1 - 30 ms | Super fast. The experience will be smooth. |
31 - 50 ms | Good. There will not be a significant delay. |
51 - 100 ms | Normal. In some intense online battles, there might be some delays. |
101 - 200 ms | Not good. It will not support a real-time online battle. |
201 - 500 ms | Bad. Delays and freezing will happen frequently. |
>500 ms | Very bad. The player can not play the game. |
Use the following reporter blocks to get the data.
Selection | Description | Example Value |
session ID | The unique ID of the player in the room. A session ID is a 9-digit code.
If the player is not in a room, the value is ‘NaN’. | 3Y546cRPc |
room ID | The unique ID of a room. A room ID is a 9-digit code.
If the player is not in a room, the value is ‘NaN’. | p425JOzrl |
room type | There are four types of return values.
- broadcast: The player is in a broadcast room.
- lobby: The player is in a lobby.
- match: The player is in a match room.
- NaN: The player is not in a room. | serverId |
Set and get extra data on the current room
Set extra data to a room. Each player in the room will obtain it.
Get extra data from the current room.
Changes in a room
When the extra data or the player’s information changes, the event will be triggered.
Selection | Description |
What is changed | Select what kind of change will trigger this event. There are three options.
- any: Any change in the room will trigger this event.
- extra data: When the extra data in the room changes, this event will be triggered.
- online count: If a player connects to or disconnects from the room, this event will be triggered. |
Property | Description | Example Value |
Session ID | The session ID of the player who changed the room state. | bgy7bgOzM |
State | Current room states in JSON format. | See below for details |
Changes | In JSON format, the current and previous values of the changed state. | See below for details |
Example value of room state:
{
"onlineCount":1,
"players":{
"w0ZHUA0iX":{
"name":"Jamin",
"scale":0,
"direction":0,
"sessionId":"w0ZHUA0iX",
"uuid":"18270013",
"extra":"data",
"connected":true
}
}
}
Example value of changes when a new player joins the room:
[
{
"op":128,
"field":"onlineCount",
"value":2,
"previousValue":1
}
]
Test
Normally, MMO game developers can't test the game by themself because one user can get only one session ID in a game.
Use the following stack block to enable or disable multi-IDs for one player.
Selection | Description |
Enable or Disable | There are two options.
- Enable: Enable multi-IDs for one player.
- Disable: Disable multi-IDs for one player. |
With multi-IDs, developers can create several characters in an MMO game by themselves.
🗺 Game Lobby
Get data of match rooms in the lobby
There can be several match rooms in a lobby. A player can obtain some basic data from each match room in the lobby.
Use the following reporter block to obtain states of a match room in the lobby.
The match room numbers start from 0. The player can obtain the following data.
Options | Description | Example Value |
room ID | The unique 9-digit ID of a room. | RiSFHUuRA |
room type | There are three return values.
- broadcast: The player is in a broadcast room.
- lobby: The player is in a lobby.
- match: The player is in a match room. | match |
clients | The current player count in the room. | 1 |
max clients | The maximum number of players the room can hold.
When the player count in the room reaches the max client number, the match room will be locked.
If there is no limitation on the player count, the value will be 'infinity'. | 5 |
created at | The time when the room was created. | Sun Jul 24 2022 12:04:35 GMT+0800 (中国标准时间) |
metadata | A JSON file containing the locked data and gid of the room. | See below for details |
extra data | Extra data varies according to the room. Players in the room can set and obtain it. | data |
locked? | If the room is locked, the value will be “true”. Otherwise, the value will be “false”.
When a match room is locked, new players are not allowed to join the room. | false |
all data in JSON | A JSON file containing all states of a match room. | See below for details |
Example value of metadata:
{
"locked":false,
"gid":"62dcbecb55e9663ece47846b-test02"
}
Example value of all data in JSON:
{
"clients":1,
"createdAt":"2022-07-24T04:30:12.387Z",
"maxClients":5,
"metadata":{
"locked":false,
"gid":"62dcbecb55e9663ece47846b-test02"
},
"name":"match",
"processId":"LoAOMOAlm",
"roomId":"Y4_eGxDG3"
}
This event will be triggered when a match room changes in the lobby.
Selection | Description |
What is changed | Select what kind of change will trigger this event. There are three options.
- any changes: Any change of rooms in the lobby will trigger this event.
- created: When a new match room is created, the event will be triggered.
- removed: When a new match room is removed, the event will be triggered. |
Property | Description | Example Value |
Rooms | The list of changed rooms states in JSON format. | See below for details |
Example value of rooms:
[
{
"clients":1,
"createdAt":"2022-07-21T05:06:51.304Z",
"maxClients":4,
"metadata":{
"locked":true,
"gid":"62d42391e189602916172fec-test01",
"extra":"{\"inGame\":0,\"winner\":\"default\"}"
},
"name":"match",
"processId":"vdXjfoyKm",
"roomId":"8D_cGWbDW"
}
]
Use this reporter block to get the match room count in the lobby.
Use the following stack block to fill the state of match rooms in the lobby into a list. To use this block, you must make a list first.
Use this reporter block to get states of match rooms in the lobby.
Selection | Description |
Kind of room | There are three options.
- all: return all rooms in the lobby.
- locked: Return all locked rooms in the lobby.
- unlocked: Return all unlocked rooms in the lobby |
Example of the return value:
[
{
"clients":1,
"createdAt":"2022-07-24T04:55:18.150Z",
"maxClients":5,
"metadata":{
"locked":false,
"gid":"62dcbecb55e9663ece47846b-test02"
},
"name":"match",
"processId":"LoAOMOAlm",
"roomId":"lleCilflR"
},
{
"clients":1,
"createdAt":"2022-07-24T04:55:20.471Z",
"maxClients":5,
"metadata":{
"locked":false,
"gid":"62dcbecb55e9663ece47846b-test02"
},
"name":"match",
"processId":"LoAOMOAlm",
"roomId":"vWVfV-lqW"
}
]
🎾 Match Game
Join or create a match room in a lobby
Use the following stack blocks to join or create a match room in a lobby.
The server ID should be the same as the server ID of the lobby.
Selection | Description |
How to connect | Select how to connect to a room. There are two options.
- Join or create: Connect to an existing room. If there is no available room. create a new one.
- Create: Create a new room. |
Property | Description | Example Value |
Server ID | The unique ID of an MMO server. | serverId |
Max players | The maximum number of players the room can hold.
When the player count in the room meets the max clients, the match room will be locked. | 5 |
Extra data | Extra data according to the player. You can set customized values to it. | data |
Use the following stack blocks to join a particular room in the lobby.
Property | Description | Example Value |
Room ID | The unique 9-digit ID of a room. | RiSFHUuRA |
Server ID | The unique ID of an MMO server. | serverId |
Extra data | Extra data according to the player. You can set customized values to it. | data |
Lock or unlock a match room
Use the following stack block to lock or unlock a room.
Selection | Description | Example Value |
Lock or Unlock | There are two options.
- Lock: Lock the match room. New players cannot join the room.
- Unlock: Unlock the match room. New players can join the room. | Lock |
✉️ Message
Broadcast messages
Use the following block to broadcast a message to other players in the room.
Property | Description | Example Value |
type | The type of this message. Receivers can determine how to use the message based on its type. | message |
content | The content of this message. | hello |
Receive a message
This event will be triggered when the player receives a message from others.
Property | Description | Example Value |
sender | The session ID of the sender. | bgy7bgOzM |
senderUID | The unique user ID of the sender. | 18270013 |
name | The user name of the sender. | Jamin |
type | The type of the message. | message |
content | The content of the message. | hello |
😽 Player
Get states of players in the room
This reporter block will return players' data in the room.
The players' data can be shown in two formats:
default: In this format, the value will contain all players' session IDs, user IDs, and user names.
For example, there are two players in the room.
w1wHX6sDi,196572628,Jamin;ShbK_dKmG,18270013,Shawn;
JSON: The value will be in JSON format. The players will be in a list, and each player is treated as an object that contains several properties. You can process JSON files with other extensions like Gandi Data Utils.
[
{
"name":"Jamin test",
"scale":0,
"direction":0,
"sessionId":"YjUOIes3M",
"uuid":"196572628",
"extra":"{\"ready\":0}",
"connected":true
},
{
"name":"Jamin test",
"scale":0,
"direction":0,
"sessionId":"Csj2Bjnp6",
"uuid":"196572628",
"extra":"{\"ready\":0}",
"connected":true
}
]
This reporter block will return the online player count of a room.
Use the following reporter block to get the data of a player with the session ID.
Selection | Description | Example Value |
Name | The name of the player. | Jamin |
X | A property which can be set to any number. Suggest setting to the x position of the player. | 100 |
Y | A property which can be set to any number. Suggest setting to the y position of the player. | 90 |
Scale | A property which can be set to any number. Suggest setting to the size of the player. | 100 |
Direction | A property which can be set to any number. Suggest setting to the direction of the player. | 90 |
Cocrea User ID | The unique user ID of the player. | 18270013 |
connected? | If the player is connected, the value will be true. Otherwise, the value will be false. | true |
Extra Data | Extra data on the player. You can assign customized values to it. | data |
All data in JSON | All data on the player in JSON format. | See below for details |
Example value of all data in JSON:
{
"name":"Jamin test",
"scale":0,
"direction":0,
"sessionId":"4MWHoPRRO",
"uuid":"196572628",
"extra":"data",
"connected":true
}
Set the value of states
Use the following stack blocks to set the states of the player.
Selection | Description |
Name | The name of the player. |
X | A property which can be set to any number. Suggest setting to the x position of the player. |
Y | A property which can be set to any number. Suggest setting to the y position of the player. |
Scale | A property which can be set to any number. Suggest setting to the size of the player. |
Direction | A property which can be set to any number. Suggest setting to the direction of the player. |
Extra Data | Extra data on the player. You can assign customized values to it. |
🙀 Player Event
When I connect to a room
This event will be triggered when the player has just joined or created a room and will get all data in the room.
When a new player connects to the room
This event will be triggered when a new player connects to the room.
Property | Description | Example Value |
sessionId | The session ID of the player. | an3r2W7bb |
name | The name of the player. | Jamin |
data | The user name of the sender. | See below for details |
Example value of data:
{
"name":"Jamin",
"scale":0,
"direction":0,
"sessionId":"an3r2W7bb",
"uuid":"196572628",
"extra":"data",
"connected":true
}
Use the following reporter block to get the data of the last connected player.
Selection | Description | Example Value |
Name | The name of the player. | Jamin |
X | A property which can be set to any number. Suggest setting to the x position of the player. | 100 |
Y | A property which can be set to any number. Suggest setting to the y position of the player. | 90 |
Scale | A property which can be set to any number. Suggest setting to the size of the player. | 100 |
Direction | A property which can be set to any number. Suggest setting to the direction of the player. | 90 |
Cocrea User ID | The unique user ID of the player. | 18270013 |
connected? | If the player is connected, the value will be true. Otherwise, the value will be false. | true |
Extra Data | Extra data on the player. You can assign customized values to it. | data |
All data in JSON | All data on the player in JSON format. | See below for details |
Example value of all data in JSON:
{
"name":"Jamin test",
"scale":0,
"direction":0,
"sessionId":"4MWHoPRRO",
"uuid":"196572628",
"extra":"data",
"connected":true
}
When a player is disconnected
This event will be dispatched when a player is disconnected.
Property | Description | Example Value |
sessionId | The session ID of the player. | an3r2W7bb |
name | The name of the player. | Jamin |
data | The user name of the sender. | See below for details |
The example value of data:
{
"name":"Jamin",
"scale":0,
"direction":0,
"sessionId":"an3r2W7bb",
"uuid":"196572628",
"extra":"data",
"connected":true
}
Use the following reporter block to get the data of the last disconnected player.
Selection | Description | Example Value |
Name | The name of the player. | Jamin |
X | A property which can be set to any number. Suggest setting to the x position of the player. | 100 |
Y | A property which can be set to any number. Suggest setting to the y position of the player. | 90 |
Scale | A property which can be set to any number. Suggest setting to the size of the player. | 100 |
Direction | A property which can be set to any number. Suggest setting to the direction of the player. | 90 |
Cocrea User ID | The unique user ID of the player. | 18270013 |
connected? | If the player is connected, the value will be true. Otherwise, the value will be false. | true |
Extra Data | Extra data on the player. You can assign customized values to it. | data |
All data in JSON | All data on the player in JSON format. | See below for details |
Example value of all data in JSON:
{
"name":"Jamin test",
"scale":0,
"direction":0,
"sessionId":"4MWHoPRRO",
"uuid":"196572628",
"extra":"data",
"connected":true
}
Unexpected situation
This event will be triggered when a player is disconnected abnormally because of network failure or similar issues.
When a player's state changes
This event will be triggered when a player's state changes.
Property | Description | Example Value |
sessionId | The session ID of the player. | an3r2W7bb |
name | The name of the player. | Jamin |
data | The user name of the sender. | See below for details |
Example value of data:
{
"name":"Jamin",
"scale":0,
"direction":0,
"sessionId":"an3r2W7bb",
"uuid":"196572628",
"extra":"data",
"connected":true
}
Use the following reporter block to get the data of the last state-changed player.
Returns the data of a particular player. Count from 0.
Selection | Description | Example Value |
Name | The name of the player. | Jamin |
X | A property which can be set to any number. Suggest setting to the x position of the player. | 100 |
Y | A property which can be set to any number. Suggest setting to the y position of the player. | 90 |
Scale | A property which can be set to any number. Suggest setting to the size of the player. | 100 |
Direction | A property which can be set to any number. Suggest setting to the direction of the player. | 90 |
Cocrea User ID | The unique user ID of the player. | 18270013 |
connected? | If the player is connected, the value will be true. Otherwise, the value will be false. | true |
Extra Data | Extra data on the player. You can assign customized values to it. | data |
All data in JSON | All data on the player in JSON format. | See below for details |
Example value of all data in JSON:
{
"name":"Jamin test",
"scale":0,
"direction":0,
"sessionId":"4MWHoPRRO",
"uuid":"196572628",
"extra":"data",
"connected":true
}
Create a clone of a player
In MMO games, we recommend you create clones to generate characters for each player.
Use the following block to create a clone of a player with a session ID.
This stack block will create a clone of the sprite with the session ID as a clone ID.
Use the following reporter block to get the data from a clone.
Selection | Description | Example Value |
Name | The name of the player. | Jamin |
X | A property which can be set to any number. Suggest setting to the x position of the player. | 100 |
Y | A property which can be set to any number. Suggest setting to the y position of the player. | 90 |
Scale | A property which can be set to any number. Suggest setting to the size of the player. | 100 |
Direction | A property which can be set to any number. Suggest setting to the direction of the player. | 90 |
Cocrea User ID | The unique user ID of the player. | 18270013 |
connected? | If the player is connected, the value will be true. Otherwise, the value will be false. | true |
Extra Data | Extra data on the player. You can assign customized values to it. | data |
All data in JSON | All data on the player in JSON format. | See below for details |
Example value of all data in JSON:
{
"name":"Jamin test",
"scale":0,
"direction":0,
"sessionId":"4MWHoPRRO",
"uuid":"196572628",
"extra":"data",
"connected":true
}
🛠 Utils
Use the following boolean block to determine whether the sprite is a clone.
Use the following boolean block to determine whether the clone represents yourself.
Use the following boolean block to determine whether the clone's session ID is the value in the block.