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.
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:
game.playingsound = true play sound (filename, wait, loop)
game.playingsound = false stop sound
That could fail to do what you want it to do for many reasons.
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).
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
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"> <gameid>bed3b089-d406-4330-a522-bd10fc946cca</gameid> <version>1.2</version> <firstpublished>2018</firstpublished> <commandpane /> <feature_advancedscripts /> <inituserinterface type="script"> JS.setCommands ("test") </inituserinterface> </game> <object name="room"> <inherit name="editor_room" /> <object name="player"> <inherit name="editor_object" /> <inherit name="editor_player" /> </object> </object> <command name="test_cmd"> <pattern>test</pattern> <script> PlaySoundCustom ("themp3.mp3", true, false) </script> </command> <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> <function name="StopSound"> game.playingsound = false stop sound </function> </asl>
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
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).