Play sound only once?

  • #1, by paedtThursday, 13. August 2015, 02:47 5 years ago
    Hey all,
    I've got a (hopefully simple) sound question. I would like to have a bit of music play once -- just once -- while clicking through a series of scenes. I know that I can sustain the music through different scenes by calling the same "play sound" action part in each scene, but is there a way to specify that once the sound has been played, never to play it again on subsequent visits?
    It seems like a pretty simple thing, but I can't figure it out.

    Thanks much!

    Newbie

    12 Posts


  • #2, by sebastianThursday, 13. August 2015, 08:54 5 years ago
    to get this clear:
    do you want to play a soundeffect or music?

    Thread Captain

    2337 Posts

  • #3, by Simon_ASAThursday, 13. August 2015, 12:06 5 years ago
    You can play your music with the "play sound" action without problem. When the music has been played once, it will stop (no loop). However be careful that the music will probably stop if you change of scene.

    If it should only play once in the game, simply use an if/else action with a condition.

    - create a new conditon (Music_Play_Once)
    - create this action list:

    If condition 'Music_Play_Once' is false
    Play Sound [your music file]
    Set condition 'Music_Play_Once' to true -- so that you can never call the music again
    End if
    1
    2
    3
    4
    5


    Is that what you wanted to do?

    Great Poster

    321 Posts

  • #4, by paedtThursday, 13. August 2015, 15:30 5 years ago
    Just to clarify, this is a short musical refrain that I'm playing as a sound effect, because there's already an ambient track taking up the 'Background music' slot.

    Thanks for the advice, Simon -- I tried something like this a short while ago, but I'm having difficulty figuring out when to set the Music_Play_Once condition to True. Since I have multiple scenes that potentially need to have this refrain playing (depending on how fast the player moves through them), I have the same "play sound" action in all of them -- that way the sound will continue. But this means I have to keep the condition False until the file has played through once completely, and I can't figure out how best to do this.

    Possibly I could do something with the "wait until sound is finished" action?

    Newbie

    12 Posts

  • #5, by Simon_ASAThursday, 13. August 2015, 17:55 5 years ago
    If it is something that you need to use often, then I recommend using "Play Sound" only (forget the condition), in a script called by other action. Just rename the text "called by other action" to something more specific, like "Refrain". So it's easier to call your sound anytime.

    You should place this script in a place where it is easy to access (in an empty scene with only some global scripts, for example).

    Then when you work in your other scenes and need to call your refrain, you just need to use an action "call/quit action" and set it on "Call", and point to the special Refrain script.

    I'm not sure it will solve your issue, I didn't exactly understand what you want to do, but hopefully you'll figure out what to do smile

    Great Poster

    321 Posts

  • #6, by sebastianThursday, 13. August 2015, 18:08 5 years ago
    you could use a variable which counts up every second. when the time of seconds is equal to the sound time, the soundeffect time is reached and you can set the condition to true.

    Thread Captain

    2337 Posts

  • #7, by paedtThursday, 13. August 2015, 19:41 5 years ago
    Aha! Yes, I've thought about using a variable like this. But how would I keep it running/counting between scenes? Same question with a 'called by other action' script.

    EDIT:
    Goodness, I'm being foolish. I didn't realise that calling an action part like what you describe would keep it running until it was specifically quit, despite scene changes. Strange this doesn't also work when calling a 'play sound' action part.
    Anyway, it's working now. Thanks for all your help, Sebastian and Simon! smile

    Newbie

    12 Posts

Write post