Why use Archive Code Extension?
When programming with Scratch, sometimes we may come across situations where we want to turn several variables and lists into a a string of characters, like making archive code.
For example, we can use the following script to make a simple archive code:
And we can use the following script to get data from the archive code (Using Suger Extension):
In more complex cases, where we want to convert lists into a string of characters, the method using separators like the script above becomes more complicated.
In that situation, we can use Archive Code Extension. With Archive Code Extension, we can make and decode archive codes conveniently.
How does the extension work?
The extension use a "container". You can store variables and lists in this "container" and convert them into an archive code, which is actually a JSON string.
Functions and Definition
Basic Blocks
Empty Container.
Clear all data stored in Container.
Add … to Container.
Add data to Container and name it.
Container in string format.
Convert the contents in Container into a string. (in JSON format actually)
e.g. Use the script below to add several values and list to Container.
And use the block below to convert all the data in Container into an archive code.
The archive code will be like:
{
"coins":100,
"handheld item":"apple",
"backpack":["oak","stone","berries"]
}
Parse string to Container.
Parse a string of archive code to Container.
e.g. Use the script below to get several data from the archive code.
If failed to parse, the block below will return false. And the original contents in Container will be preserved
e.g. Run the script below, the parse failed, and the original contents in Container won’t change.
Get contents in Container.
Use the block below to get the corresponding content of the name.
Use the following blocks to save content to variable or list.
Auxiliary Blocks
Get the amount of contents in Container.
For example, if there are two variables and a list that contains two items in Container, the block will return 3. (two variables and a list)
Get … of the xth content
Get certain information of the xth content
Property | Description |
Name | The name of the content |
Value | The value of the content |
Type | The type of the content (variable or list) |
Length of list | The length of the list (return blank character if the content is not a list) |
If Container contains…
determine whether Container contains content with certain name.
Length of the list
return the length of the list with certain name.
(return blank character if the content is not a list or the list doesn’t exsit)
#… of the list
Get the xth content in certain list.
#… of the list
Delete content with certain name in Container.
Additional Blocks
Encrypt / decrypt … with key …
These blocks are used to encrypt / decrypt something. You can use them to encrypt archive code.
What does the “key” do: only both keys in encryption and decryption match, the text can be correctly decrypted.
For example, you can use players’ userID as the key, so that only the correct person can decrypt the text correctly and get the text.
Copy … to clipboard.
Copy something to the clipboard. It can be used to copy the archive code.
Get Unicode of… / get character of Unicode …
Get the code of a character. The code ranges from 0 to 65535. For example, Unicode of character “A” is 65.
Those two blocks can be used to make your own encryption algorithms.
Best Practices
Make An Archive Code
Make and read archive codes with the following scripts:
Make A Cloud Archive
Use the following scripts to make the cloud archive:
Use with Simple MMO
As we know, in Simple MMO Extension, every player has only one extra data,which make it hard to store multiple data of the player.
In this case, we can use Archivecode Extension like this:
What’s more, when using boardcasting in Simple MMO, sometimes we may need to boardcast a message with multiple information.
Then we can use the script like below:
Other situations where we need to store multiple information in one variable…
For example, supposed that we want to store several tile maps in a list, and we hope that each map only occupies one item in the list.
Then we can convert all information of a map into a string of characters with Archivecode Extension, so that we can save them in a list conveniently.
Roadmap and Logs
Version | Log / What’s New |
1.0 | Added:
The initial version. |