From Test-Scratch-Wiki

Translate: - English 
DocumentInQuestion.png 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.

As of Scratch 2.0, users can create Cloud Variables. Cloud variables are special variables that stay the same after the project is closed. 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. By the time you are done with this tutorial, you should understand how to create and maintain a cloud list.

Encoding and Decoding

To store strings in your cloud list, we will have to encode and decode strings into number format. We are going to create our own encoder and decoder. This will enable basic strings to be stored into a compact number format. Start by making a Custom Block...

define encode (string1)

and create an iterator, which is a special name for a variable that loops through data. You'll also need a variable for the output (the encoded numbers that the encoder spits out)

set [i_encode v] to (1)
set [output v] to ()

Connect this block to the encode definition. We'll need our iterator to spin through the string we're encoding, so we'll add a repeat C-block and tell it to repeat the length of the string. Here's our full code so far...

define encode (string1)
set [i_encode v] to (1)
repeat (length of (string1) // loops through the string
change [i_encode v] by (1)
end

This block is halfway done — there just needs to be a few extra things. Create two lists with all the letters you would like to encode — for example, a list would be the alphabet and punctuation, each character on a separate item in the list. There should be 99 or less characters in this list.

Next, we need to add a mini-loop inside of our first loop. This will find the correct two-letter number to add to the final output.

Here is the script:

set [i_findLetter v] to (1)
repeat (length of [letters v])
if <(item (i_findLetter) of [letters v]) = (item (i_encode) of (string1))> then
if <(length of (i_findLetter)) = (1)>
set [output v] to (join (output)(join (0)(i_findLetter))
else
set [output v] to (join (output)(i_findLetter))
end
change [i_findLetter v] by (1)
end

References

  1. http://scratch.mit.edu/discuss/topic/4789/