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
  • textshown - the contents of the "say" message every iteration

Script

definetypewritetexthowlong?secask?askspeed:speedsettextshowntosetito1initializevariablesrepeatlengthoftextitisrequiredtorepeatto'typewrite'everylettersettextshowntojointextshownletterioftextthiswilltaketheprevioustextshownandaddthenextlettersaytextshowndisplaytextchangeiby1iteratewait1/speedsecswaitforalittlebit,basedonspeedendifaskthenchecksifitshouldasktheresultingtextasktextandwaitifso,askstextelsewaitsecsecsifnot,waitalittlelongertoreadsaysaynothingto'delete'textoffofthemessageend

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