Scratch/Как собрать перечень имен участников

Материал из Letopisi.Ru — «Время вернуться домой»
Перейти к: навигация, поиск

https://wiki.scratch.mit.edu/wiki/Simple_Username_Cloud_List


This page will show you how to make a relatively simple username cloud list.

Содержание

Variables and Lists (Part one: Encoding)

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 two 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)?>> 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]

You will need to create this in order to use a custom block. Defining this block will come later.

define find character (character)::custom

You might also want to do this to manually add usernames:

repeat (length of (name)) // "name" holds the username that you 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, make 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)

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::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.
Make this script:

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]


Персональные инструменты
Инструменты
Акция час кода 2018

организаторы проекта