From Test-Scratch-Wiki

(Redirected from Eng:Cloud Lists)

SandCastleIcon.png This page has links to outside of the Scratch website or Wikipedia. Remember to stay safe when using the internet as we can't guarantee the safety of other sites.
The process to create a cloud variable in Scratch 3.0 is much the same as creating a regular variable; the only difference is checking the "cloud variable" box.
The note that appears after creating the first cloud variable in a project.

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.[1] It may use a different font if one's computer does not support it. Cloud data logs can be removed by the person who created the project. For example, if there is a test and someone does not want their score shown, but it goes onto the log, the creator can remove the log. There is a limit of ten cloud variables per project.

Cloud-icon.png

They update automatically, as opposed to requiring refreshing before updating. While the update is not instant, it is usually relatively quick.

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[2]

Cloud data may not be used by New Scratchers. The Scratch Team does not want people new to Scratch misusing cloud variables, as it could put a large load on the system that it cannot handle (see section "Issues with Cloud").

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.

Functionality

Cloud variables are maintained through a secure Websockets connection.

To avoid overloading the cloud data infrastructure, cloud data updates are limited to a certain number per second when a project is being run. One should always avoid attempting to update a cloud variable in a fast loop that does not wait between updates. Generally, one should carefully consider how often a cloud variable is updated and try to limit any updates to only times when it is needed, such as when the value actually changes, and to limit how often the variable is updated.

If variable is being updated too often, the cloud data server will drop the connection temporarily and updates will not be sent to the cloud data servers until the connection is automatically re-opened after a variable waiting period.

Cloud data has a limit of up to ten (10) cloud variables per project. It was accidentally limited to eight immediately after the relase of 3.0.[3] Cloud variables can contain only numbers (unlike regular variables, they cannot contain letters). A character limit of 256 digitsTemplate:Cite post per variable has also been implemented (formerly 128 digits). Hexadecimal numbers are no longer supported.Template:Cite post

Cloud List Engines

Cloud list engines are projects or scripts that store lists in cloud variables. To do this, they encode lists as a number, and set a cloud variable to said number. 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 each letter a number from 1 to 26. A couple of examples of cloud list engines are here and here. You can use base 11 for only numbers and convert it to base 10. than to decode it, first you have to convert to base 11.

Example Uses

  • High score
if <(local score) > (☁ high score)> then
  set [☁ high score v] to (local score)
else
  say [You didn't beat the high score!]
  • Win/Loss (so long as scores don't end in zero digit)
if <(human score) > (computer score)> then
  set [☁ won v] to (join (join (human score) [.]) (computer score))
else
  set [☁ lost v] to (join (join (human score) [.]) (computer score))
  • Surveys
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
  • Encoding for receiving on the other end for projects with Human Communication
if < [whitelist v] contains (answer) ?> then
    encode (answer)::custom
    set [Player_1_chat v] to (result)
  else
     say[That word is not in the Whitelist so cannot be sent!]
end
  • Example function to encode base-10 text
define Encrypt (Input)
set [charList v] to [         abcdefghijklmnopqrstuvwxyz234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1.-!@#$%^&*()_+|\\:";'<>?/,` =]
set [inputL# v] to [1]
set [Encoded v] to []
delete (all v) of [Return v]
delete (all v) of [eFull v]
repeat (length of (Input))
  if <not <(letter (inputL#) of (Input)) = [ ]>> then
    Case Check (letter (inputL#) of (Input)) :: custom
    if <(letterCase) = [lowercase]> then
      set [lList# v] to [10]
      repeat until <<(letter (inputL#) of (Input)) = (letter (lList#) of (charList))> or <(lList#) > [44]>>
        change [lList# v] by (1)
      end
      if <not <(lList#) > [44]>> then
        add [0] to [eFull v]
        add (letter (1) of (lList#)) to [eFull v]
        add (letter (2) of (lList#)) to [eFull v]
      end
      change [inputL# v] by (1)
    else
      if <(letterCase) = [uppercase]> then
        set [lList# v] to [45]
        repeat until <<(letter (inputL#) of (Input)) = (letter (lList#) of (charList))> or <(lList#) > [73]>>
          change [lList# v] by (1)
        end
        if <not <(lList#) > [73]>> then
          add [0] to [eFull v]
          add (letter (1) of (lList#)) to [eFull v]
          add (letter (2) of (lList#)) to [eFull v]
        end
        change [inputL# v] by (1)
      else
        if <(letterCase) = [other]> then
          set [lList# v] to [74]
          repeat until <<(letter (inputL#) of (Input)) = (letter (lList#) of (charList))> or <(lList#) > (length of (charList))>>
            change [lList# v] by (1)
          end
          if <not <(lList#) > (length of (charList))>> then
            add [0] to [eFull v]
            add (letter (1) of (lList#)) to [eFull v]
            add (letter (2) of (lList#)) to [eFull v]
          end
          change [inputL# v] by (1)
        end
      end
    end
  else
    add [0] to [eFull v]
    add [9] to [eFull v]
    add [8] to [eFull v]
    change [inputL# v] by (1)
  end
end
set [Encoded v] to (eFull :: list)
add (Encoded) to [Return v]

Cloud Data History

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). To get onto the log simply click on the cloud data button at the bottom of a project page. This will then show you the users who changed the cloud data and at what time. If the user changes cloud data blocks not in their own project the cloud data will not be saved. Cloud Data log.png

Upon the release of Scratch 3.0, the Scratch Team mistakenly set the limit to eight cloud variables per project instead of ten.[4] On January 9, this was fixed.

Sharing Broadcasts

Cloud data is similar to Mesh. Both features allow sharing of variables across multiple simultaneous uses of the same project. By using variables, cloud data can also simulate broadcasts across projects, as shown in the scripts below:

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]
. . .
when key [space v] pressed::hat events //This script will "broadcast"
set [☁ broadcast v] to [1]

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 Hexadecimal

Archive.png This article or section documents a feature not included in the current version of Scratch (3.0). It is only useful from a historical perspective.

Numbers 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 a project requires lots of storage in Cloud Variables). To encode a base-10 number into a base-16 number one could run the following script (assuming that a whole number [integer] is being converted):

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 base-22 can be used 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, the following custom blocks must be used:

define letter number of (character) in (string)
set [counter v] to [1]
set [output v] to [0] //This will be what happens if it is not found
repeat (length of (string)) //For every character
if <<(character) = (letter (counter) of (string))> and <case sensing :: grey>> 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 [1] //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"

Issues with Cloud

In October of 2016, the cloud infrastructure started to fail occasionally.[5] As a result, many multiplayer focused projects did not work correctly. This has been attributed to the ever increasing number of active users who are using cloud variables, with some projects sending up to 30 requests per cloud variable per second.[6] This effectively "spammed" the cloud server with a load that couldn't be handled by the current infrastructure and shut it down.[7]

Current Status

As a temporary fix, cloud variables have switched to using a different polling method, which is more reliable but significantly slower. Furthermore, the polling interval time was increased, to prevent spam. This new method works, but may cause cloud variables to "rubber band" and reset to a previous value after it has been changed, as well as making many multiplayer projects less "real-time" or completely breaking them in general.

Long-term

As of August 2017, a new cloud data system was in beta.[8] It used secure websockets as the communication channel. To use the new system, one could add ?newcloud to the end of the URL address to a project. The system is now the default.[9]

See Also

References

  1. ar-post:1127806
  2. https://scratch.mit.edu/info/faq/#clouddata
  3. https://scratch.mit.edu/discuss/topic/331439/
  4. https://scratch.mit.edu/discuss/topic/331439/ "The maximum number of cloud variables allowed in a project was mistakenly limited to eight rather than ten. This limit is now 10 variables again!"
  5. TheLogFather. (7/10/2016). "Cloud currently down...[title]" https://github.com/LLK/scratch-flash/issues/1211
  6. TheLogFather. (2/11/2016). "The point I'm trying to make is about changing the cloudvar(s) at every pass through a loop, i.e. something like 10-20x per second. This effectively 'spams' the cloud server." https://github.com/LLK/scratch-flash/issues/1211#issuecomment-257654646
  7. thisandagain. (27/10/2016). "Hi @TheLogFather, our Cloud Variables infrastructure is simply unable to keep up with the load that we experience generally between noon and 6pm ET." https://github.com/LLK/scratch-flash/issues/1211#issuecomment-256414214
  8. jwzimmer. (23/8/2017). "The new cloud data work has been deployed as a soft launch (accessible by specific URLs) on Production." https://github.com/LLK/scratch-flash/issues/1211#issuecomment-324073462
  9. colbygk. (11/9/2017). "Clouddata has now been migrated to the new websockets based platform and ?newcloud is no longer required to have a project use it." https://github.com/LLK/scratch-flash/issues/1211#issuecomment-328386028
Cookies help us deliver our services. By using our services, you agree to our use of cookies.