Playing sounds one after another

Below is a very simple modification of the previous example: when “chime” is entered a timer is started for two seconds, after which a sound is played. As ever this is all pretty minimal - real code should check if timer events (and sound, for that matter) are supported by the interpreter.

[code]“Sound Experiment” by David Kinder

Include Glulx Entry Points by Emily Short.

Use direct event handling.

The Sound Stage is a room. “Enter ‘chime’ to play a chime.”

Sound of Chiming is the file “Chime1.aiff”.

Playing chimes is an action applying to nothing. Carry out playing chimes:
request timer events;
say “The chimes will start playing soon.”

Understand “chime” as playing chimes.

Glulx input handling rule for an independent of the player g-event:
if the current glk event is a timer-event:
cancel timer events;
play Sound of Chiming.

To request timer events:
(- glk_request_timer_events(2000); -)

To cancel timer events:
(- glk_request_timer_events(0); -)
[/code]