|It has been suggested that this page's contents be merged with the page Data_Blocks. You can discuss this on the page's talk page.|
Cloud data is a feature that allows users to store variables "in the cloud", or on the server. Cloud variables have the character "☁" (a cloud icon in the font Scratch uses) in front of them, to distinguish from regular variables:
They update automatically, as opposed to requiring refreshing before updating. They do not refresh instantly, however; they lag about 2 seconds between updates.
|“||If both Scratchers have a reasonably fast Internet connection (DSL/Cable), and there are no restrictive firewalls on the computers/network, updates should be transmitted in milliseconds. However, a lot of computers have firewall software running in them, and if the firewall software blocks outgoing connections to TCP port 531 and TCP port 843, the time-lag becomes one-second.||”|
– FAQ Page
Cloud data may not be used by New Scratchers. The Scratch Team does not want people new to Scratch crashing the server or taking up space because they may not know what they are doing.
Cloud variables use the regular blocks associated with variables. The only difference is that the value is truly global, and is reflected across all copies of the project being viewed on the Scratch Website.
Cloud data is referred to as "persistent" in the code and some early development versions.
Since Cloud Data is stored on the server, cloud variables cannot be used in the offline editor.
Currently, cloud data has been stripped down to only (up to 10) cloud variables that can contain only numbers. This means that cloud variables, unlike regular variables, cannot contain letters. A character limit of 10,240 digits per variable has also been implemented, which translates to 300.7 KB of cloud data storage per project. The Scratch Team says they want to configure the server bit-by-bit to add new features incrementally.
Though this limits the kinds of projects that can be made, one can still make a reasonable variety of projects that have interaction with an arbitrary number of computers.
Cloud List Engines
Cloud list engines are pieces of code that attempted to turn a list into only numbers to be stored inside of a cloud variable. Later, the same code can turn the cloud variable back into a list. This was developed based on the idea that anything in the world can be represented with numbers. For example, all letters in the alphabet could be stored as number by assigning a number from 1 - 26 to each letter. Most popular examples of cloud list engines include:
- https://scratch.mit.edu/projects/22003344/ by Lirex - https://scratch.mit.edu/projects/10096959/ by RelRel
- High score
if <(local score) > (☁ high score)> then set [☁ high score v] to (local score) else say [You didn't beat the high score!]
ask [Vote for Pepsi or Coke! Which is your favorite?] and wait if <(answer) = [Pepsi]> then change [☁ pepsi votes v] by (1) else if <(answer) = [Coke]> then change [☁ coke votes v] by (1) else say [Sorry! That answer wasn't recognized.] end
When the Scratch Team released the beta version of cloud data, they set up public logs for projects with cloud data in them showing the time cloud data was modified, who modified the data, the current value of the data, and the type of action of the data modification (such as del_var, rename_var, and set_var).
when gf clicked set [old broadcast v] to (☁ broadcast) forever if <not <(old broadcast) = (☁ broadcast)>> then broadcast [cross-project message v] set [old broadcast v] to (☁ broadcast) when I receive [cross-project message v] . . . // category=grey
when key [space v] pressed::hat events //This script will "broadcast" set [☁ broadcast v] to An optimized version would replace
broadcast [cross-project message v]for
broadcast (☁ broadcast)with a When I Receive block for each possible broadcast.
Due to cloud data limitations, a project using this method of broadcasting can only use broadcasts with numbers for messages.
Using HexadecimalNumbers encountered everyday are called "base 10" or "decimal" numbers. This is because 10 different digits are used (0 through 9). However, hexadecimal (often shortened to "hex") is another way of representing numbers. It uses 16 different digits. Since 16 digits do not exist when working with base-10, the "digits" a-f are used to represent digits 10 through 15. This means that "14" in base-10 is "e" in base-16. Cloud Data supports base-16, if the value starts with a "0x". For example, to set a Cloud Variable to "e" (14) you would run the block
set [☁ Variable v] to [0xe]Since each digit of a hexadecimal number stores more information than its decimal equivalent, it may help store more data before reaching the character limit (useful if your project requires lots of storage in Cloud Variables). To encode a base-10 number into a base-16 number you could run the following script (assuming that you are converting a whole number [integer]):
define convert to base-16 (number) set [digits v] to [0123456789abcdef] set [output v] to  set [temp v] to (number) repeat until <(temp) = (0)> set [output v] to (join (output)(letter (((output) mod (16)) + (1)) of (digits))) //Remainder on division by 16 set [temp v] to (([floor v] of (temp)) / (16)) end //Use (output) //to get the result from this.
To convert back, simply run any of the following blocks and they will all return the base-10 value of the block:
((☁ HexVariable) + (0)) ((☁ HexVariable) - (0)) ((☁ HexVariable) * (1)) ((☁ HexVariable) / (1))
Scratch retains the case of the hexadecimal digits, so it will remember if a variable was saved as "0xe" or "0xE" on the Cloud. To detect case read this article. Therefore you can use base-22 by using uppercase A-F and lowercase a-f as separate digits, to produce the 22 digits: "0123456789abcdefABCDEF". This will no longer allow for simple conversion back to base-10. To convert from base-22 to base-10, you must use the following custom blocks:
define letter number of (character) in (string) set [counter v] to  set [output v] to  //This will be what happens if it is not found repeat (length of (string)) //For every character if <<(character) = (letter (counter) of (string))> and <Check that the case matches too here>> then //If a match is found set [output v] to (counter) stop [this script v] end define to base-10 (hex) set [placevalue v] to  //Represents how much each hex digit is worth set [counter v] to (length of (hex)) //Represents the digit it is decoding set [result v] to  //This will store the final output //It starts from the end and works its way back repeat (length of (hex)) letter number of (letter (counter) of (hex)) in [0123456789abcdefABCDEF] set [result v] to (join (result) ((output) * (placevalue))) change [counter v] by (-1) //Because it is working in reverse set [placevalue v] to ((placevalue) * (16)) end //The base-10 output is stored in the variable "result"
It should be noted that while hexadecimal numbers sometimes contain letters, they are representing a digit.