Simple Username Cloud List

Материал из Поле цифровой дидактики
Версия от 11:33, 21 июля 2022; Patarakin (обсуждение | вклад) (1 версия импортирована)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)

Шаблон:Cloud Data This page will shows how to make a relatively simple username cloud list.

Variables and Lists (Part one: Encoding)

Create two lists: 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.

You also need 2 cloud variables. One is the encoded username, the other is the next available slot in the list, set to 1.

Character List

Next, add this script:

when flag clicked
delete all 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])
replace item (☁ current slot) of [Players v] with (username)
if <not <[Players v] contains (username)?>> then
change [☁ current slot v] by (1)

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 five 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 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

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