Sound

From AGI Wiki
(Redirected from Sound Command)
Jump to navigationJump to search

The sound command plays a loaded sound resource.

Syntax

sound(byt SOUNDNUM, flg fDONE);

Remarks

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, new.room, new.room.v, restart.game, restore.game or save.game 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.

Example

Code:

<syntaxhighlight lang="agi"> load.sound(22); sound(22, f99); if(isset(f99))

 {
 print("sound is done playing.");
 reset(f99);
 }

</syntaxhighlight>

Technical Information

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

See Also

Sound Commands