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. (November 2015)

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. This tutorial should explain how to create and maintain a cloud list.

Encoding and Decoding

To store strings in a cloud list, strings will need to be encoded and decoded into number format. 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. 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. Another variable will be needed 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 encoding definition. The iterator will need to spin through the string being encoded, so add a repeat C-block and tell it to repeat the length of the string. Here's the 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)

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

Next, a mini-loop needs to be added inside of the 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)> then
set [output v] to (join (output)(join (0)(i_findLetter))
set [output v] to (join (output)(i_findLetter))
change [i_findLetter v] by (1)


  1. topic:4789