Scratch Cat saying "Hello!" with the Say block

A typewriter or teletype effect is a text effect where text is shown letter by letter, instead of all at once (the default behavior). This article provides a tutorial on how to make such an effect, displaying the text with the say block.

Setup

This script requires two variables, as well as a custom block:

  • (i) - a variable used for iteration
  • (displayed text) - the contents of the "say" message every iteration
  • define say text [text] with delay [delay]

The "text" argument will be the text to progressively say, and the "delay" argument is how long to wait between each character. Note that Scratch runs at 30 FPS so some smaller wait times will be noticeably rounded.

Script

say text [Hello, world!] with delay [0.1]
define say text [text] with delay [delay]
set [displayed text v] to [] // initializing the text to an empty string
set [i v] to [1] // counter
repeat (length of (text)) // loop over the characters in the string
    set [displayed text v] to (join (displayed text) (letter (i) of (text))) // joins together the next character
    say (displayed text)
    change [i v] by (1) // increment counter to go to the next character
    wait (delay) secs // wait before showing the next character
end
Note Caution: Don't set the custom block to "run without screen refresh" as this will try to type the entire text instantly. This is not the desired effect and the wait block will cause significant lag.

A project example can be found here.

See Also

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