Logo
  • Features
  • Educators
  • What's New
  • Blog
  • Showcase
  • About us
  • Contact
Try it now!
How to Choose between Cloud Variables, the KV Database, and Simple MMO?
☁️

How to Choose between Cloud Variables, the KV Database, and Simple MMO?

What are cloud variables, KV database, and Simple MMO?

Most Scratch games are single-player. To make it possible to share data between all computers running a project, the Scratch team designed a feature called cloud variables. Scratchers can store number-containing variables in the cloud and build online multiplayer games with cloud variables.

Because of its mechanism, this feature has some limitations. Therefore, permissions are set for the feature:

Cloud data can not be used by New Scratchers. The Scratch Team does not want people new to Scratch misusing cloud variables, as it could put a large load on the system that it cannot handle, most likely leading to the feature not working. - Cloud Data wiki page

To solve issues with cloud variables, Gandi IDE built the KV database in Data Utils and Simple MMO.

image
image

In this article, these three features will be introduced. You can make your choice based on your situation.

Mechanisms

There are four concepts that need to be considered in network transmission:

  1. Permission: Who can read or write the data?
  2. Load: How much data is transferred each time?
  3. Time limit: How often does the data need to be synchronized?
  4. Persistence: Does the data need to be stored for a long time?

Cloud Variables

Permissions

Cloud variables are like public spaces. Everyone can read and write. Creators should build a permission system to avoid conflicts. For example, set up several cloud variables, where each one can only be written by one player.

Load

Cloud variables don’t supports differential transmission. That means all data will be transferred to everyone when only a small part of it is changed.

Time limit

The more frequently data is written, the larger the amount of data. Because of the forever loop, this could happen in Scratch projects easily.

Persistence

The data of cloud variables will be persistent.

Cloud variables are maintained through a secure Websockets connection. To avoid overloading the cloud data infrastructure, cloud data updates are limited to a certain number per second when a project is being run. One should always avoid attempting to update a cloud variable in a fast loop that does not wait between updates. Generally, one should carefully consider how often a cloud variable is updated and try to limit any updates to only times when it is needed, such as when the value actually changes, and to limit how often the variable is updated on the server. If a variable is being updated too often, the cloud data server will drop the connection temporarily and updates will not be sent to the cloud data servers until the connection is automatically re-opened after a variable waiting period. There is a limit of ten (10) cloud variables per project. Cloud variables can contain only numbers (unlike regular variables, they cannot contain letters or symbols). A character limit of 256 digits per variable has also been implemented (formerly 128 digits). Hexadecimal numbers are no longer supported. - Cloud Data wiki page

KV Database

KV (Key-value) database holds key-value pairs. For example, if a variable is named ‘a’, and the value of it is 123, it will be saved as a=123 in KV database. It is easy to read and use.

Permission

In K-V database, each project has a public space and private spaces. For example, if a key-value pair is saved in private spaces with the key ‘password’, each player can write and read their own value of ‘password’ but cannot write or read others’.

Load

KV database supports differential transmission. If a user updates the value of a key, only this pair will be transferred.

Time limit

KV database supports high-frequency writing and reading and the data is cached. In other words, when the data is not updated, you can read the data without network transmission.

Persistence

The data of KV database will be persistent.

Creators can replace cloud variables with KV database for better performance in load and permission.

Simple MMO

Simple MMO supports communication. The data can be high-speed synced between different players. It will be a better choice to make a game that needs real-time communication, such as PUBG or Among Us.

The mechanism of network transmission is totally different between cloud variables and KV database. The most obvious advantage of Simple MMO is speed.

Permission

The permission system in Simple MMO is very strict. Each player can only write their own states. In addition, players can broadcast messages to others. It can be used to build a chat system or dispatch events in local projects. It’s like the broadcast between sprites in Scratch.

Load

Simple MMO supports differential transmission. Only changed parts will be transferred. It will greatly reduce the excess load in the transmission to support real-time communication.

Time Limit

Thanks to the low load, Simple MMO has the best real-time performance.

Persistence

Simple MMO is not designed to record. When the player is disconnected, the data will be deleted.

Comparison

Service
Cloud variables
KV database
Simple MMO
Permissions
Public
Public and private
Private writing permission
Load
High
Low
Very low
Lag
High
Medium
Low
Persistence
Supported
Supported
Not supported
Usability
Very easy
Easy
Easy to use, hard to understand
Scenario
1. Learn about network
1. Save players’ settings 2. Build a save & load system
1. Build real-time chat rooms 2. Make online multiplayer games
Suggestion
Only use for learning 1. Use KV database to store data 2. Use Simple MMO for real-time communication
Use to store players’ data and game settings 1. Use Simple MMO for real-time chat room and state syncing
Use for real-time communication and event communication 1. Use KV database to store scores and data

Scenarios

No.1 Adjust game settings without re-sharing the project

Some creators want to adjust the difficulty of a game based on feedback from players.

Creators want to adjust some settings in a game without updating and re-sharing the project.

In this situation, you can use two blocks in KV database.

write:

image

read:

image

For example, you want to adjust the difficulty. The project needs to identify you as the creator and run the script to adjust difficulty.

Step 1: Build a difficulty system controlled by parameters

In most games, there are parameters determining the difficulty, such as the amount of enemies, the speed of characters, and the damage of weapons.

Step 2: Identify the creator

You can use the username in Sensing to identify yourself. For example:

image

Step 3: Write parameters

You can define rules to write parameters in KV database. For example, you can press number keys to write parameters:

image
image

Step 4: Read parameters

Other players who run the project should read the latest values of parameters and set them to match local variables . For example:

image

No.2 Store the coin count

This scenario is similar to the first one. In this case, the count of coins can only be written and read by players themselves. You need to save data in private spaces.

write:

image

read:

image

You can make a block to change the count of coins. First, read the value of ‘coins’ from the private space. Then, change the value. Finally, write it back to the database. For example:

image
☝
Tips: You may noticed that these scenarios are also achievable with cloud variables. The difference is: 1. There are separated writing and reading operations to avoid conflict. 2. There are public and private spaces in KV database for safety and efficiency.

No.3 Create a real-time chat room or a real-time PvP game

[This part will be updated soon. Check it later.]

Postscript

Is it impossible to build an online multiplayer game with cloud variables? The answer is absolutely not.

Some Scratchers have built well-functioning online multiplayer engines and games in Scratch based on cloud variables.

scratch.mit.edu

scratch.mit.edu

slither.io by griffpatch

scratch.mit.edu

scratch.mit.edu

Among Us by TimMcCool

All these solutions have built-in encoding and decoding system. It is a challenge for developers to build an efficient one. These creators are brilliant.

Gandi IDE built Simple MMO and Data Utils to provide basic functionalities which are more suitable for developing online services and make doing so more achievable for new creators.

Acknowledgments

Thanks to the Scratch team. They build cloud variables that inspired a lot of creators to make online games.

Thanks to all creators and developers who helped Gandi IDE to build Data Utils and Simple MMO. Some of them are: Nick, yk1boy, pikachu, Oscar, Arkos, bob, Jamin.

💡
If you have any questions or suggestions, you can find us in the discord channel: https://discord.gg/U3nyveCvRa
Logo

Designed by 2ndR with love

Discord