Why use Data Utils?
In Scratch, we love Cloud Variables. Scratchers can use them to store data and build online multiplayer games.
On the other hand, Cloud Variables are hard to use when you need to process complex data.
Gandi IDE presents Data Utils to replace Cloud Variables when you need to store and process complex data in the cloud server.
If you want to build multiplayer games, Gandi IDE presents Simple MMO to make this easier.
What is JSON?
JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is also easy for machines to parse and generate. You can visit https://www.json.org/ to understand it better.
Gandi Data Utils introduce JSON to Scratch to process complex data.
Modules
Module | Description |
☁️ Cloud Data | - Set and get key-value pairs in the cloud server
- Send events with code and data |
🏷️ JSON Utils | - Utils to process data in JSON format |
Functions and Definitions
☁️ Cloud Data
Set a key-value pair in the cloud server.
Input and Selection | Description | Example Value |
key | The key to storing the value | key |
value | The value paired to the key | 0 |
scope | With which scope the data will be stored. There are two options.
- user data: The data can only be obtained by the user who set it in this project.
- project data: The data can be obtained by all users who run this project. | - |
Get the value with a key.
Input and Selection | Description | Example Value |
key | The key you want to get the value with | key |
scope | With which scope the data will be stored. There are two options.
- user data: The data can only be obtained by the user who set it in this project.
- project data: The data can be obtained by all users who run this project. | - |
🏷️ JSON Utils
Check if the input is a valid object or array. This reporter block will return true or false.
Input and Selection | Description | Example Value |
input | The input you want to check | [1, 2, 3] |
object or array | There are three options.
- array: An ordered collection of values. For example, [1, 2, 3].
- object: A non-ordered set of key/value pairs. For example, {name:’Brad’, age:20, likesCoding:true}.
- object or array: Input is an array or an object. | - |
Get the value stored with the key in an object.
Input | Description | Example Value |
key | The key you want to get the value with | key |
object | A non-ordered set of key/value pairs. For example, {name:’Brad’, age:20, likesCoding:true}. | {"key":"value"} |
Sometimes, the object can be complex. For example:
{ "name":"Shawn",
"age":-1,
"projects":[
{"name":"Gandi IDE","url":"https://getgandi.com/"},
{"name":"Cocrea","url":"https://cocrea.world/"}
]
}
To get the first object in the array of “projects”, you should use the key:
projects[0]
The returned value will be:
{
"name":"Gandi IDE",
"url":"https://getgandi.com/"
}
To get the url of Gandi IDE, you should use the key:
projects[0].url
The returned value will be:
https://getgandi.com/
You can also do some calculations with this block. For example:
The return value will be 43.
Set a new value for a key in an object. This block will return the new object.
Input | Description | Example Value |
new value | The new value you want to set | new value |
key | The key you want to assign the new value to | key |
object | An object defined by a set of properties, each consisting of a key and a value. For example, {name:’Brad’, age:20, likesCoding:true} | {"key":"value"} |
Replace a list with an array, or insert an array into a list.
Input and Selection | Description | Example Value |
replace or insert | There are two options:
- replace: The items in the list will be replaced.
- insert: The items in the array will be added to the list. | - |
list | You can choose one of the lists in the project | - |
array | An ordered collection of values. For example, [1, 2, 3]. | [1, 2, 3] |
Parse a list to an array.
Selection | Description | Example Value |
list | You can choose one of the lists in the project | - |
method | There are two options:
- try converting values to objects: If there are items in object format, convert them to objects.
- do not convert values: All items will be converted to strings. | - |