Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Help with displaying usernames on scoreboards
- hellu23
-
Scratcher
7 posts
Help with displaying usernames on scoreboards
Hi! Just trying to make a simple project but for some reason I cant make the top players username display after restart. Here are the blocks I used to make it.
when green flag clicked
forever
if <(Score) > [(☁ high score)]> then
set [(☁ Player) v] to (username)
end
end
Last edited by hellu23 (Nov. 5, 2023 15:22:22)
- Sasha--seals
-
Scratcher
31 posts
Help with displaying usernames on scoreboards
That won't work because cloud variables only support numbers. You will have to convert the username into numbers. This is how to do that:
My signature will probably be down there so don't add that to your project. |
|
V
when green flag clicked
set [chars v] to [abcdefghijklmnopqrstuvwxyz0123456789_-]
set [j v] to [1]
repeat (length of (chars))
add (letter (j) of (chars)) to [char_list v]
end
forever
if <(Score) > (☁ highscore)> then
encode (username)
set [☁ player_with_high_score v] to (encoded)
set [☁ highscore v] to (Score)
define encode (text)
set [encoded v] to []
set [i v] to [1]
repeat (length of (text))
if <(length of (item # of (letter (i) of (text)) in [char_list v])) = [1]> then
set [encoded v] to (join (encoded) (join (0) (item # of (letter (i) of (text)) in [char_list v])))
else
set [encoded v] to (join (encoded) (item # of (letter (i) of (text)) in [char_list v]))
end
change [i v] by [1]
My signature will probably be down there so don't add that to your project. |
|
V
Last edited by Sasha--seals (Nov. 5, 2023 16:15:43)
- coading_101
-
Scratcher
22 posts
Help with displaying usernames on scoreboards
Well i think you can just do:
when green flag clicked
forever
say (username) for (2) secs
end
- coading_101
-
Scratcher
22 posts
Help with displaying usernames on scoreboards
Or maybe something like:
when green flag clicked
forever
if <(☁ score) > [☁️high-score]> then
set [Username score v] to (username)
end
say [username score v]
end
- Sasha--seals
-
Scratcher
31 posts
Help with displaying usernames on scoreboards
Well i think you can just do:when green flag clicked
forever
say (username) for (2) secs
end
I think @hellu23 is trying to display the username of the person who has set the highest score. The script that you made will just display the username of the person who is using the project.
- Sasha--seals
-
Scratcher
31 posts
Help with displaying usernames on scoreboards
Or maybe something like:when green flag clicked
forever
if <(☁ score) > [☁️high-score]> then
set [Username score v] to (username)
end
say [username score v]
end
You have to encode the username into numbers.
- hellu23
-
Scratcher
7 posts
Help with displaying usernames on scoreboards
Thanks for the help! Though I'm going to be real, I didn't really understand the whole code so I'm going to take a look at it in the morning
.
.- hellu23
-
Scratcher
7 posts
Help with displaying usernames on scoreboards
That won't work because cloud variables only support numbers. You will have to convert the username into numbers. This is how to do that:After I took a second look I can finally say that I don't understand the second part. I later tried to recreate the program which helped to understand it better but it doesn't work since the result I am getting is just a lot of 0 in the variable.when green flag clicked
set [chars v] to [abcdefghijklmnopqrstuvwxyz0123456789_-]
set [j v] to [1]
repeat (length of (chars))
add (letter (j) of (chars)) to [char_list v]
end
forever
if <(Score) > (☁ highscore)> then
encode (username)
set [☁ player_with_high_score v] to (encoded)
set [☁ highscore v] to (Score)
define encode (text)
set [encoded v] to []
set [i v] to [1]
repeat (length of (text))
if <(length of (item # of (letter (i) of (text)) in [char_list v])) = [1]> then
set [encoded v] to (join (encoded) (join (0) (item # of (letter (i) of (text)) in [char_list v])))
else
set [encoded v] to (join (encoded) (item # of (letter (i) of (text)) in [char_list v]))
end
change [i v] by [1]
My signature will probably be down there so don't add that to your project. |
|
V
- hellu23
-
Scratcher
7 posts
Help with displaying usernames on scoreboards
Ok I found a way which was to change from encoded blank to encoded set to username in the beginning of the define part, but that still leaves you with a lot of 0 at the end of the variable.That won't work because cloud variables only support numbers. You will have to convert the username into numbers. This is how to do that:After I took a second look I can finally say that I don't understand the second part. I later tried to recreate the program which helped to understand it better but it doesn't work since the result I am getting is just a lot of 0 in the variable.when green flag clicked
set [chars v] to [abcdefghijklmnopqrstuvwxyz0123456789_-]
set [j v] to [1]
repeat (length of (chars))
add (letter (j) of (chars)) to [char_list v]
end
forever
if <(Score) > (☁ highscore)> then
encode (username)
set [☁ player_with_high_score v] to (encoded)
set [☁ highscore v] to (Score)
define encode (text)
set [encoded v] to [(username)]
set [i v] to [1]
repeat (length of (text))
if <(length of (item # of (letter (i) of (text)) in [char_list v])) = [1]> then
set [encoded v] to (join (encoded) (join (0) (item # of (letter (i) of (text)) in [char_list v])))
else
set [encoded v] to (join (encoded) (item # of (letter (i) of (text)) in [char_list v]))
end
change [i v] by [1]
My signature will probably be down there so don't add that to your project. |
|
V
Edit: I was once again wrong that only works in the short run and disappears on reload.
Last edited by hellu23 (Nov. 6, 2023 11:42:40)
- ProfessorUelf
-
Scratcher
100+ posts
Help with displaying usernames on scoreboards
Can you share your project, so we can take a look at your code to find the error?
- hellu23
-
Scratcher
7 posts
Help with displaying usernames on scoreboards
Can you share your project, so we can take a look at your code to find the error?Didn't do much on the project but here is the link Your text to link here….
Thanks for your help in advance
.- hellu23
-
Scratcher
7 posts
Help with displaying usernames on scoreboards
To be more specific I left the code on the first sprite and a comment beside it
- mean_ice_cream
-
Scratcher
56 posts
Help with displaying usernames on scoreboards
you have to encode it because you cant put letters in cloud variables. You could probably do this by giving each letter a number then encode and decode them.
- MathPuppy314
-
Scratcher
500+ posts
Help with displaying usernames on scoreboards
@griffpatch has made a nice concise tutorial on the subject of encoding/decoding text into cloud variables. Here is the link. His tutorial is aimed at making a full real-time cloud multiplayer game, however the encoding/decoding part of it is relevant to your need.
I think he does a good job of getting you to really understand why a certain script is there and what exactly it does.
I think he does a good job of getting you to really understand why a certain script is there and what exactly it does.
Last edited by MathPuppy314 (Nov. 7, 2023 03:44:10)
- hellu23
-
Scratcher
7 posts
Help with displaying usernames on scoreboards
Thanks everyone I will take a look at it
- Sasha--seals
-
Scratcher
31 posts
Help with displaying usernames on scoreboards
I also made a project that has a lot of useful blocks, including the “encode” block that i put in the second comment, so you can just go here: https://scratch.mit.edu/projects/919480924/ and go inside the Cloud Scripts sprite which has the “encode” block.
Last edited by Sasha--seals (Nov. 8, 2023 00:10:02)
- Discussion Forums
- » Help with Scripts
-
» Help with displaying usernames on scoreboards





