In other languages

Help the wiki!

The Scratch Wiki is made by and for Scratchers. Do you want to contribute?

Learn more about joining as an editor!

See discussions in the Community Portal


A chatroom is a project where Scratchers (New Scratchers cannot use cloud data) can talk to each other in real time using cloud data. Due to the current restrictions on cloud data, creating a chatroom project is difficult and the potential is fairly limited.

Warning Warning: No matter how close you feel to someone on Scratch, never share personal information (like your birth date, real name, password, where you live) or agree to meet up in public with them.

Rules Governing Chatroom Projects

Document.png This article or section needs additional citations for verification. Its information may not be accurate. Editors can help by adding references. (February 2018)

Only "whitelist chats" (a.k.a. "safe chats") may be created, where users can choose from a preselected list of messages.[1] Free chats or blacklist chats, where users can post any message or where certain specific words/phrases are not allowed but otherwise messages are unrestricted, respectively, are not allowed,[citation needed] as there is a significant potential for bullying (more so than other places since users think only a few people will see their messages) or personal information being revealed and it would be very difficult for the Scratch Team to moderate them.

Warning Note: The Scratch Team does not encourage the creation of chat rooms.[citation needed] If someone needs to be told something, use the comments, which are usually much safer, and monitored more closely by the Scratch team.


This tutorial makes a "safe chat" with the messages:

  • Hello!
  • Bye!
  • How was your day?
  • Fine.

Variables needed

This tutorial will assume several variables. These are:

  • c
  • i
  • j
  • k
  • ☁data

One list called "Chat" will be used too. This list will show the chat log.

Sending a message

To send a message to the chat room, first add the message to the list "Chat".

define chat [msg]
add (join (join (username)[:])(msg)) to [Chat v]

Next, encode the entire chat log to ☁data. This process runs through every character in every list item and encodes the character as a two-digit number, then add "00" to separate list items since there is no 0th character of a piece of text. Both define blocks need to have "run without screen refresh" checked when making them.

when gf clicked
set [c v] to [abcdefghijklmnopqrstuvwxyz0123456789_-.?!:�] // These are all supported username characters + characters in our messages + colon for separation of user and message + one "unknown character" character for contingencies.
define encode
set [i v] to [0]
set [☁data v] to []
repeat (length of [Chat v])
    change [i v] by (1)
    set [j v] to [0]
    repeat (length of (item (i) of [Chat v]))
        change [j v] by (1)
        set [k v] to [0]
        repeat until <<(letter (j) of (item (i) of [Chat v])) = (letter (k) of (c))> or <(k) > (length of (c))>>
            change [k v] by (1)
        if <(k) > (length of (c))> then // if such a character is out of range of c...
            set [k v] to (length of (c)) // ...replace that letter with the "unknown character" character
        if <(k) < [10]> then // if the resulting number is less than two digits long...
            set [☁data v] to (join (☁data) (join [0](k))) // ...make it two digits by adding a 0 in front, e.g. 4 becomes 04
            set [☁data v] to (join (☁data) (k))
    set [☁data v] to (join (☁data) [00])

Receiving a message

To see messages on the list that have been sent, decode ☁data into our list. This will take every two characters of ☁data and turn them back into a text character.

define decode
set [i v] to [1]
delete (all v) of [Chat v]
add [] to [Chat v]
repeat ((length of (☁data)) / (2))
    if <(join (letter (i) of (☁data))(letter ((i) + (1)) of (☁data))) = [00]> then
        add [] to [Chat v]
        replace item (last v) of [Chat v] with (join (item (last v) of [Chat v])(letter (join (letter (i) of (☁data))(letter ((i) + (1)) of (☁data))) of (c))
    change [i v] by (2)
delete (last v) of [Chat v]

User Interface

To make an interface to send and receive messages, simply always ask for a message, then send it. Preferably, this would be in the Stage.

when gf clicked
    ask [Message id here: 1. Hello! 2. Bye! 3. How was your day? 4. Fine.] and wait
    if <(answer) = [1]> then
        chat [Hello!] :: custom
    if <(answer) = [2]> then
        chat [Bye!] :: custom
    if <(answer) = [3]> then
        chat [How was your day?] :: custom
    if <(answer) = [4]> then
        chat [Fine.] :: custom
    encode :: custom // actually put the message in the cloud chat
    decode :: custom // verify that the message is there and view new messages

See Also


  1. jvvg. (10/5/2013). "If you want to make a chat program, you may make a “safe” chat, where users can only select from a few messages."
  • This page was last modified on 16 February 2018, at 01:39.