(Redirected from Saving Usernames to the Cloud)

This page will shows how to make a relatively simple username cloud list. Due to New Scratcher limitations, the cloud list can not be used by New Scratchers.

Variables and Lists (Part one: Encoding)

Create two variables: one for characters (letters, numbers, etc.), and another for the players. The player list will be the only one shown in the final product, so a suitable name would be "Players".

Next, create another two variables. The names of these do not matter, because they will not show, but make sure they can be easily distinguished.

Only one cloud variable is required for this cloud list, unless over 400 Scratchers use the program. The name of this variable does not matter.

Character List

Next, add this script:

when flag clicked
delete [all v] of [Characters v]
set [item v] to [1]
set [chars v] to [ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890-_]
repeat (( length of (chars)) + (1))
  add (letter (item) of (chars)) to [Characters v]
  change [item v] by (1)
end

Username Adding Script

Create the following script to encode a Scratcher's username.

when I receive [Add Username v]
set [Variable 1 v] to [1]
if <not <[Players v] contains (username)?>> then
if <not <(username) = [ ]>> then
repeat (length of (username))
find character (letter (Variable 1) of (username))::custom
change [Variable 1 v] by [1]
end
set [☁ CLOUD DATA v] to (join (☁ CLOUD DATA) [00])
add (username) to [Players v]

Add the following definition hat; its code will be added later.

define find character (character)::custom

Use this script if manually adding names is necessary:

repeat (length of (name)) // "name" holds the username that someone want to add.
find character (letter (Variable 1) of (name)) ::custom
change [Variable 1 v] by [1]
end
set [☁ CLOUD DATA v] to (join (☁ CLOUD DATA) [00])

Define Find Character Script

Now, add the first define script. It should look like this:

// The below should have already been created.
define find character (character)
set [Variable 2 v] to [1]
repeat until <(item (Variable 2) of [Characters v] :: list) = (character)>
change [Variable 2 v] by (1)
end
if <(Variable 2) < [10]> then
  set [☁ CLOUD DATA v] to (join (☁ CLOUD DATA) (join [0] (Variable 2)))
else
  set [☁ CLOUD DATA v] to (join (☁ CLOUD DATA) (Variable 2))
end

Variables and Lists (Part two: Decoding)

Create seven more normal variables. This tutorial names them as follows:

(data item)
(decoded)
(build username)
(uv1)
(uv2)

Main Script

Now, add this script:

when flag clicked
delete [all v] of [Players v]
set [uv1 v] to [1]
set [uv2 v] to [2]
set [data item v] to [01]
repeat (450)
decode character::custom
wait (0.05) secs
if <(data item) = [ ]> then
broadcast [Add Username v]
stop [this script v]
end
end
broadcast [Add Username v]
Note Note: The number "450" in the repeat block does not have to be 450;
It can be anything, but just keep in mind that this number is the maximum amount of usernames that will be added to the Players list. If this number is 35 and a 36th Scratcher clicks the green flag and gets their username data saved then clicks the flag again, it will send duplicate data. Keep this number higher than the total views of the project.

Decoding Blocks

This is the last script. It is also the most complicated.

define decode character::custom
set [build username v] to [ ]
if <(☁ CLOUD DATA) = [ ]> then
stop [this script v]
end
repeat until <(decoded) = [00]>
set [data item v] to (join (letter (uv1) of (☁ CLOUD DATA)) (letter (uv2) of (☁ CLOUD DATA)))
set [decoded v] to (item (data item) of [Characters v])
set [build username v] to (join (build username) (decoded))
change [uv1 v] by (2)
change [uv2 v] by (2)
if <(join (letter (uv1) of (☁ CLOUD DATA)) (letter (uv2) of (☁ CLOUD DATA)))=()> then
stop [this script v]
end
end
add (build username) to [Players v]

See Also