From Test-Scratch-Wiki

2.0 Username block.png
Category Sensing
Type Reporter
Introduced in 2.0

The Username block is a sensing block and a reporter block. It reports the username of the user viewing the project, which can be used for saving progress in a project, either with a variable encoder or cloud lists (once they are released with string-storage capabilities), as well as other purposes. If no user is signed in, this block returns the empty string.


Originally, the Scratch Team was reluctant to add this block because it could compromise users' privacy.[1] They started with the User ID block, which gave an anonymous but effective way of recognizing users for a specific project. However, they eventually decided to replace it with this block because it is easier for beginners to understand and was so frequently requested.

As a safety measure, all projects that sense your username have warnings attached. If one wants to be anonymous, log out before viewing the project. However, it was complained that the message was too exaggerated.[2] Alongside, the warning appears if the backpack had a script with the username block, no matter if the project had a username block or not.[3]

Example uses

  • Saying hi to the user viewing the project
say (join [Hi ] (username))
  • Checking if the user has visited before, using Cloud Data

(Note: Cloud lists have not come out yet, so you would have to make your own cloud list.)

if <not <[☁ visitors v] contains (username)>> then
  add (username) to [☁ visitors v]
  say [Welcome back again!]
  • Checking if the viewer is logged in
when gf clicked
if  <(username) = []> then//a logged off user reports a blank response
say [Hi new user!] for (2) secs 
  • Creating a high score list
  • An "admin" list in a safe chat
when gf clicked
if <[admins v] contains (username)?> then//The "admins" list will likely have the project owner, all of their alternate accounts, and possibly all Scratch Team members
broadcast [admin v]

See Also

— this block's predecessor


Cookies help us deliver our services. By using our services, you agree to our use of cookies.