Real-Time Delays

version 1/100607 by Erik Temple

  • Home page
  • Beginning
  • Previous



  • Example: ** Teletype - Shows how to use real-time delays to mimic a teletype effect, with a short pause after each letter, and a longer pause after each line. The code here makes use of three global variables to set the speed for different types of output--delay for line breaks and paragraph breaks can be set separately from other characters. A few other phrases are included to show how common tasks such as changing the basic teletype rate can be made easier.

    It should be noted that interpreters based on Windows Glk have poor temporal resolution, perhaps 20-90 milliseconds. These include Windows Glulxe (WinGlulxe) and Windows Git. The Gargoyle and Zoom interpreters both implement a much better timer and should give better results.

         "Teletype"

        Include Real-Time Delays by Erik Temple.

        The Lab is a room. The computer is a device in the Lab.

        Current teletype character delay is a number variable. The current teletype character delay is 40.
        Current teletype line break delay is a number variable. The current teletype line break delay is 400.
        Current teletype paragraph break delay is a number variable. The current teletype paragraph break delay is 400.

        To teletype (text-to-be-printed - an indexed text):
            repeat with N running from 1 to the number of characters in the text-to-be-printed:
                if character number N in the text-to-be-printed is "[line break]":
                    wait (current teletype line break delay) milliseconds before continuing;
                if character number N in the text-to-be-printed is "[paragraph break]":
                    wait (current teletype paragraph break delay) milliseconds before continuing;
                say "[character number N in the text-to-be-printed][run paragraph on]";
                wait (current teletype character delay) milliseconds before continuing, strictly.

        To teletype (text-to-be-printed - an indexed text) at/with (speed - a number) ms/milliseconds/-- delay/--:
            change the current teletype character delay to the speed;
            teletype the text-to-be-printed.
        
        To say change teletype delay to (speed - a number) ms/milliseconds/--:
            change the current teletype character delay to speed.
            
        Instead of switching on the computer:
            say "[line break]";
            teletype "[change teletype delay to 40 ms]Cross-referencing subacoustic interlaces. . . [line break]";
            teletype "Calibrating pre-Devonian energetic imbalances. . . [line break]" with 20 ms delay;
            teletype "Preparing final systems. . . [line break]Ready." with 5 ms delay;
            say "[paragraph break]".

        Test me with "turn on computer".