How to Make a Typewriter Effect

Материал из Поле цифровой дидактики

A typewriter 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 a typewriter effect.

Variables

First, create these local variables.

  • (i) - a variable used for iteration
  • (text shown) - the contents of the "say" message every iteration

Script

define typewrite (text) how long? (sec) ask? <ask> speed: (speed)
set [text shown v] to []
set [i v] to [1] // initialize variables
repeat (length of (text)) // it is required to repeat to 'typewrite' every letter
set [text shown v] to (join (text shown) (letter (i) of (text))) //  this will take the previous text shown and add the next letter
say (text shown) // display text
change [i v] by (1) // iterate
wait ((1) / (speed)) secs // wait for a little bit, based on speed
end
if <ask> then // checks if it should ask the resulting text
ask (text) and wait // if so, asks text
else
wait (sec) secs // if not, wait a little longer to read
say [] // say nothing to 'delete' text off of the message
end

This block can now be used multiple times by dragging the custom block out and filling out the parameters.

Usage

The parameters to be filled in, in order, are:

  • The text to be shown
  • The number of seconds to wait after the typewriting is finished
  • "yes" if the typewriting should end by asking the text as a question, leave it blank otherwise. (If this is "yes", leave the number of seconds to wait blank.)
  • The number of characters per second to show. For example, if this is set to 5, every second 5 more characters will have appeared.

Шаблон:Caution

See Also