"Answer" redirects here. For the information that this block reports, see Answer (value).
Answer
answer
Category Sensing
Type Reporter
Introduced in 1.4

The answer block is a sensing block and a reporter block. The block returns the most recent text inputted with the ask () and wait block. When nothing has been inputted yet, the value will hold nothing. It was introduced in Scratch 1.4.

This block can be displayed as a Stage monitor.

Example Uses

As this block stores inputted text, it is very useful where a script has to refer to what has been inputted. For example, there are chat bots that allow the user to input their name. If the script must access their name, the answer block can be used.

Some common uses for the answer block:

  • Storing information (such as in projects that require a name to be inputted)
when green flag clicked
ask [What's your username?] and wait
if < ( answer ) = ( username ) > then
    say [That's your username!]
else
    say [That's not your username!]
end
  • Retrieving information (such as when the name must be retrieved)
ask [What's your favorite color?] and wait
say (join (answer) [ is my favorite color too!] )
  • When a setting has been inputted with the Ask () and Wait block, keeping the selecting setting somewhere
when green flag clicked
ask [Which level do you want to play?] and wait
set [level v] to (answer)
broadcast (join [ start level ] ( level ) )
  • When quizzing
when green flag clicked
ask [What is 30 + 9?] and wait
if <(answer) = [39]> then
    say [Correct!]
    change [score v] by (1)
else
    say [Incorrect]
    change [score v] by (-1)
end

See Also