From Test-Scratch-Wiki
This page will show you how to make a relatively simple username cloud list. Unfortunately, the cloud list will only be affected by Scratchers (New Scratchers can not affect cloud data).
Variables and Lists (Part one: Encoding)
First of all, you will need to create two lists; one for characters (letters, numbers, etc.) that will be used, and another for the players. The player list will be the only one shown in the final product, so perhaps consider naming it Players.
You will need to create four variables. The names of these do not matter: They will not show, but make sure you can easily tell them apart.
Only one cloud variable is needed for this cloud list, unless you get more than 400 individual users to use your program. The name of this variable does not matter.
Character List
What you need to do now is this:
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
Now, you must make a script to encode someone's username.
It should look like this:
when I receive [Add Username v] set [Variable 1 v] to [1] if <not <[Players v] contains (username)>> if <not <(username) = [ ]>> repeat (length of (username)) find character (letter (Variable 1) of (username))//category=custom change [Variable 1 v] by [1] end set [CLOUD DATA v] to (join (CLOUD DATA) [00]) add (username) to [Players v]
You will need to create this in order to use a custom block. Defining this block will come later.
Define find character (character)
You might also want to do this to manually add usernames:
repeat (length of [INSERT USERNAME TO BE MANUALLY ADDED HERE!]) find character (letter (Variable 1) of [INSERT USERNAME TO BE MANUALLY ADDED HERE!])//category=custom change [Variable 1 v] by [1] end set [CLOUD VARIABLE v] to (join (CLOUD VARIABLE) [00])
Define Find Character Script
Now, make the first define script.
It should look like this:
Define find character (character) //this block should have already been created. Use it! set [Variable 2 v] to (character) set [Variable 3 v] to [1] set [Variable 4 v] to [false] repeat until <(Variable 4) = [true]> if <(letter (1) of (item (Variable 3) of [Characters v])) = (character)> set [Variable 4 v] to [true] if ((Variable 3) < [10] ) set [CLOUD DATA v] to (join (☁CLOUD DATA) (join [0] (Variable 3))) else set [CLOUD DATA v] to (join (☁CLOUD DATA) (Variable 3)) end else change [Variable 3 v] by [1] set [Variable 4 v] to [false] end end stop [this script v]
Variables and Lists (Part two: Decoding)
Now, you will want to create seven more regular variables. In this tutorial, they are named as follows:
(data item) (decoded) (build username) (uv1) (uv2)
Main Script
Now, make 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 (data item) // category=custom wait (0.05) secs if <(data item) = [ ]> broadcast [Add Username v] stop [this script v] end end broadcast [Add Username v] stop [this script v]
![]() | 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.
Make this script:
Define decode character (N) set [build username v] to [ ] if <(CLOUD DATA) = [ ]> 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))))=()> stop [this script v] end end add (build username) to [Players v] stop [this script v]