From AGI Wiki
Revision as of 21:49, 22 April 2019 by Andrew Korson (Talk | contribs) (Remarks)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The sound command plays a loaded sound resource.


sound(byt SOUNDNUM, flg fDONE);


When the sound command is called, AGI first checks to see if another sound is already playing. If so, AGI stops that sound (setting its 'done' flag to TRUE). Then flag fDONE is reset to FALSE.

If the sound is valid, AGI then activates a vector function that begins asynchronously playing the sound (meaning it plays in the background while AGI continues to run through interpreter cycles).

If reserved flag f9 (sound enabled) is false, the sound won't play, but the check for f9 does not occur until after the vector function tries to play the sound; it immediately cancels playback of sound and then sets flag fDONE to true.

When the sound stops playing for any reason (usually by reaching the end of the resource, or by issuing the stop.sound command) flag fDONE is set to TRUE. Other situations that will stop a sound from playing and set the 'done' flag are resetting f9 (sound enabled) to FALSE or using a pause, quit,,,, or command. If any trappable error is raised, the sound will also stop and have flag fDONE set to TRUE.

Possible Errors

After resetting fDONE, AGI validates that sound resource SOUNDNUM is loaded. If it is not, AGI raises trappable error #9 and the command ends without doing anything else.


sound(22, f99);
  print("sound is done playing.");

Technical Information

Required Interpreter Version: Available in all AGI versions.
Byte-Code Value: 99 (0x63 hex)

See Also

Sound Commands