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?

Or...

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:
http://media.textadventures.co.uk/games/PHVys9dICUiMSSpr_m9WYQ/warnings.html

Here's the documentation:
http://media.textadventures.co.uk/games/PHVys9dICUiMSSpr_m9WYQ/documentation.html

Instructions with screenshots:
http://media.textadventures.co.uk/games/PHVys9dICUiMSSpr_m9WYQ/AudioVideoLibInstructions.html

How to add a library to a game (just for completion's sake):
http://media.textadventures.co.uk/games/PHVys9dICUiMSSpr_m9WYQ/addingthelibrary.html

And, finally, the library:
http://media.textadventures.co.uk/games/PHVys9dICUiMSSpr_m9WYQ/AudioVideoLib.aslx


PS

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

http://textadventures.co.uk/games/view/phvys9dicuimsspr_m9wyq/audiovideolib


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:

https://www.w3schools.com/tags/av_prop_ended.asp

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">
    <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 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).


Log in to post a reply.

Support

Forums