(☁ var)
|
This article or section uses Cloud Data. Users who are New Scratchers or are using the Offline Editor cannot make projects using Cloud Data or use it in other users' projects. To use Cloud Data, the Scratcher status is needed and the Online Editor has to be used. |
![]() |
It has been suggested that this page's contents be merged with the page Encoding and Decoding Cloud Data. You can discuss this on the page's talk page. (November 2015) |
![]() |
This article is a stub. It may be incomplete, unfinished, or have missing parts/sections. If the article can be expanded, please do so! There may be suggestions on its talk page. (July 2021) |
![]() |
This page or section is in question as to whether it is useful or not. You can discuss whether you think it should be deleted or not on its talk page. (December 2023) Reason: Near duplicate of Encoding and Decoding Cloud Data |
As of Scratch 2.0, users can create Cloud Variables. Cloud variables are special variables stored in servers. These can only store numbers. Obviously, there is a limitation to this, and many users have wanted cloud strings and lists and suggested them multiple times in the Suggestions forum.[1]
There is a workaround for making cloud lists that work, and many users have created "engines" for them for other users to use. This tutorial will describe how to build and use a cloud list. This tutorial should explain how to create and maintain a cloud list.
Encoding and Decoding
Note that the following tutorial under this section may seem similar to the one found on the page Encoding and Decoding Cloud Data; however, a few blocks differ. To store strings in a cloud list, strings will need to be encoded and decoded into number format. This is because Cloud Variables can only store numbers and will not store letters. This tutorial will show how to create one such encoder and decoder. This will enable basic strings to be stored into a compact number format.
Variables/Lists Needed
Variable names are kept short for faster script execution. The variables assumed by this method are:
(z) //Stores an alphanumeric string of accepted characters to be encoded/decoded (i) //The following ‘i’ variables are used as counters within script execution loops (i2) (i3) (☁ data) (encoded) (decoded)
Also, create the following list:
(key::list)
Encoding
For example, if the first letter of the encoding process is "b", the code representing "b" would be 12
because the twelfth letter of the variable "z" is "b". The variable that contains all the letters used for parsing is named "z" because each time the variable's value is called, a shorter name takes up less processing power to report the specified character.
when gf clicked delete all of [key v] set [z v] to [0123456789abcdefghijklmnopqrstuvwxyz-_ "',!~] //Note that the "~" symbol at the end separates each item in the list and can be replaced with any character of your choice that is not previously mentioned in the "z" variable. set [i3 v] to (1) repeat (length of (z)) add (letter (i3) of (z)) to [key v] change [i3 v] by (1) end set [encoded v] to () set [decoded v] to () define encode(data) set [encoded v] to () set [i v] to (1) repeat(length of(data)) if <(item # of (letter (i) of (data)) in [key v])<(10)> then set [encoded v] to (join (encoded)(join(0)(item # of (letter (i) of (data)) in [key v]))) else set [encoded v] to (join (encoded)(item # of (letter (i) of (data)) in [key v])) end change [i v] by (1) end
Decoding
Decoding takes the encoded number data and compiles a list out of it. Modifications must be made with the encoder and decoder if multiple lists need to be compiled for a project's particular purposes.
define decode (data) set [decoded v] to () set [i2 v] to (1) repeat ((length of (data))/(2)) set [decoded v] to (join(decoded)(item (join (letter (i2) of (data))(letter ((i2) + (1)) of (data))) of [key v]) change [i2 v] by (2)
Creating the Server
Next, you will need to create the scripts that run in the background and bring your cloud list to life.
when gf clicked delete all of [server v] decode (☁data) define countItems set [i5 v] to (1) set [i6 v] to (0) repeat (length of (☁data)) if <(join(letter(i5)of(☁data))(letter((i5)+(1))of(☁data)))=(length of [key v])> then change [i6 v] by (1) end change [i5 v] by (2) end when gf clicked set [i11 v] to (0) forever delete all of [server v] countItems decode(☁data) repeat (i6) add () to [server v] end set [i7 v] to (1) set [i8 v] to (1) repeat (length of (☁data)) if <not <(letter(i8)of(decoded))=[~]>> then replace item (i7) of [server v] with (join(item (i7)of[server v])(letter(i8)of(decoded))) else change [i7 v] by (1) end broadcast [update v] and wait end when I receive [update v] set [i10 v] to (1) delete all of [Cloud List v] //create a list called "Cloud List"; this list will be your cloud list. repeat (length of [server v]) add (item (i10) of [server v]) to [Cloud List v] change [i10 v] by [1] end if <(i11)=[1]> then wait (1) seconds delete (i12) of [server v] set [i9 v] to (1) set [encoded2 v] to () repeat (length of [server v]) encode (join(item(i9)of[server v])[~]) set [encoded2 v] to (join(encoded2)(encoded)) change [i9 v] by (1) end set [☁data v] to (encoded2) set [i11 v] to [0] end
Adding and Removing Items
Finally, here are the scripts that program two different Custom Blocks. These custom blocks let you add and remove items in your cloud list.
define addItem (item) encode (join(item)[~]) set [☁data v] to (join(☁data)(encoded)) define removeItem(itemNumber) set [i12 v] to (itemNumber) wait (0) seconds //This block may seem useless, but it is used to prevent bugs because the computer will wait for the timeframe that it takes to run a block. set [i11 v] to (1)