Question About Sound

I'm looking for a way to activate a flag every time a sound is played, without having to script it in for every instance in a game. So my question is this:

Is there a script that can be modified that runs every time a sound is played?


Is there an attribute/variable that changes every time a sound is played?

Thanks in advance.


Ignore this. I was being silly.

Your silliness is overpowering though!


Well, I had posted some code . . .

. . . but it would have set the flag in a newly created function which also called the play sound script. Then, there was another newly created function which disabled the flag and called the stop sound script.

The problem was there was no simple way to have Quest disable the flag itself once the sound had finished playing.

If that doesn't matter:

Create PlaySound function.

Parameters: filename, wait, loop

game.playingsound = true
play sound (filename, wait, loop)

Create StopSound function.

(No parameters.)

game.playingsound = false
stop sound

That could fail to do what you want it to do for many reasons.

Javascript would probably be a better way to handle it, but that can get complicated when setting Quest attributes (unless you're using Quest 5.8).

My AudioVideoLib should allow you to do anything you want.

Start with the WARNINGS page:

Here's the documentation:

Instructions with screenshots:

How to add a library to a game (just for completion's sake):

And, finally, the library:


A link to the main page, just in case something gets updated and one (or more) of the above links dies:

I guess I should explain what I was trying to accomplish more thoroughly:

My game plays a lot of sound effects (that wait, but don't loop). Most of my rooms also play a background sound (that doesn't wait, but does loop). If a sound effect plays, it will silence the ongoing, looping background sound. I want a flag to be set every time a sound effect plays, so that a turnscript can decide, at the end of the turn, whether to restart the background sound (because flag is set), or to just allow the ongoing background sound to continue without interruption (because flag is not set). Right now the game is set up to just restart the background sound every turn, but having the background sound loop from turn to turn, whenever possible, would be more immersive and less distracting.

There must be at least a hundred instances where a sound effect is played (hence my searching for a more automated solution). This game does use Quest 5.8, by the way. I could try your AudioLib, KV, but it would require a major overhaul of my game, and I was trying to avoid that (sorry).

I think in that case, it would make more sense to have a javascript function restart the background sound, rather than a turnscript. Or to create a JS function which plays a sound unless it is already playing.


It seems like there is a way to check if any sound at all is currently playing via JS, but I can't remember what it is...

I shall research this and return.

I found this:

But this only checks if a specific element has ended, not all sounds.


What about using the two functions I posted above and adding game.playingsound = false to the script to run after the sound is finished playing?

Then, you could check the game.playingsound boolean, but I don't know what that would accomplish when using the "wait" during play sound.

Here's a silly example (you'll have to substitute my audio file with one of your own to test it):

<!--Saved by Quest 5.7.6606.27193-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="SoundCheck">
    <commandpane />
    <feature_advancedscripts />
    <inituserinterface type="script">
      JS.setCommands ("test")
  <object name="room">
    <inherit name="editor_room" />
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
  <command name="test_cmd">
      PlaySoundCustom ("themp3.mp3", true, false)
  <function name="PlaySoundCustom" parameters="filename, wait, loop">
    game.playingsound = true
    msg ("DEBUGGING:  Sound playing: " + GetBoolean (game, "playingsound"))
    play sound (filename, wait, loop)
    game.playingsound = false
    msg ("DEBUGGING:  Sound playing: " + GetBoolean (game, "playingsound"))
  <function name="StopSound">
    game.playingsound = false
    stop sound

You see, I may as well just set a flag after every sound effect is played, then my turnscript will restart background sounds or not, depending on the state of the flag. Ideally, my turnscript could first call a JS function to check if any sound is currently playing or not, instead of depending on flags to signify this. If JS is not feasible, I'll just set flags then.


You can do that for online players, but not for desktop users. I don't really know how the desktop player uses Chromium to play the audio with the play sound script (and I tried really hard to learn for a long time), but I'm pretty sure you can't access it from within the game.

...but, if you use HTML to load the audio rather then the play sound script, you can do damned near anything you want using Javascript. (This is also the case with my library, which uses HTML and JS, but has it all set up for you to use the GUI to do everything.)

Ok, the next game I make, I will use your audio/vid library, KV. Thanks.

I didn't mean to sound glib : )


Well... you did.

Just kidding! I wouldn't add a library to a game unless I was in the early stages of writing. You're cool (and the gang).

This topic is now closed. Topics are closed after 60 days of inactivity.