From Test-Scratch-Wiki

Encoding a cloud variable is the process where one takes a list and compiles it into a number-only format in a cloud variable. It can be used for creating large online leader-boards or even massive multiplayer online games.

Variables Needed

This tutorial will assume a few variables. These are:

  • z
  • i
  • i2
  • i3
  • ☁ data

A single list, named users, will also be used.

In this example, the project will keep track of users who visit it. However, it is trivial to replace the users list with something else. Alternately, the list and repeat blocks can be removed to only encode a single variable.


The encoding process takes each item in a list, separates them with a certain number, such as 00, and assigns each item a (preferably two-digit) number.

This project assumes that it separates them with the code 00. The code 00 is used in the following script to separate list items because no character in the variable "z" has an indexed position of 0. In simpler terms, when the cloud variable is encoded, each letter of each item of the list is added as a number. The number represents the letter in the variable "z" (which lists all characters) by which the character from the list meets its equivalent position.

For example, if the first letter of the encoding process is "b", the code representing "b" would be 12 because the second 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
set [z v] to [0123456789abcdefghijklmnopqrstuvwxyz?] //the variable name is kept short for faster script execution

define encode
set [i v] to [0]
set [☁ data v] to []
repeat (length of [users v])
    change [i v] by (1)
    set [i2 v] to [0]
    repeat (length of (item (i) of [users v]))
        change [i2 v] by (1)
        set [i3 v] to [0]
        repeat until <<(letter (i2) of (item (i) of [users v])) = (letter (i3) of (z))> or <(i3) > (length of (z))>>//if the letter is not included in the variable "z" the loop will not end, 
            change [i3 v] by (1)
        if <(i3) > (length of (z))>//so it checks if "i3" is greater than the length of "z"
            set [i3 v] to [37] // and replaces the letter with a "?" if that is true
        if <(i3) < [10]> then //If i3 is less than 10, it needs to be ex: 03 instead of 3
            set [☁ data v] to (join (☁ data) (join [0] (i3)))
            set [☁ data v] to (join (☁ data) (i3))
    set [☁ data v] to (join (☁ data) [00])


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
set [i v] to [1]
delete (all v) of [users v]
add [] to [users v]
repeat ((length of (☁ data)) / (2))
    if <(join (letter (i) of (☁ data)) (letter ((i) + (1)) of (☁ data))) = [00]> then
        add [] to [users v]
        replace item (last v) of [users v] with (join (item (last v) of [users v]) (letter (join (letter (i) of (☁ data)) (letter ((i) + (1)) of (☁ data))) of (z)))
    change [i v] by (2)
delete (last v) of [users v]

See Also

Cookies help us deliver our services. By using our services, you agree to our use of cookies.