Frictional Games Forum (read-only)

Full Version: Is there a way to stop a looping sound?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm playing a snt file with several sounds which is looping but I just noticed that StopSound isn't working. The sound keeps playing. I'm pretty sure it's because of the looping/saving. Is there a proper way to make looping sound stop?
How are you playing the looping sound? Via the editor or via script? If script, you must simply give the internal name of the sound you started in the stop script for it to find it. Remember to actually include a name in the start script, otherwise you can't stop it.

If you started it via the editor "Sound" object, then I'm not certain if it has a default name you can stop via script or not, but if you only want it to play once and never loop, you can copy the .snt file and edit it to be loop="false", then use that in your story instead.
(03-27-2018, 11:25 AM)Mudbill Wrote: [ -> ]How are you playing the looping sound? Via the editor or via script? If script, you must simply give the internal name of the sound you started in the stop script for it to find it. Remember to actually include a name in the start script, otherwise you can't stop it.

If you started it via the editor "Sound" object, then I'm not certain if it has a default name you can stop via script or not, but if you only want it to play once and never loop, you can copy the .snt file and edit it to be loop="false", then use that in your story instead.
Via script PlaySoundAtEntity. I gave the sound an internal name and the sound is playing at a script area. I copied the internal name in the StopSound script. All of the the script is working, except that the sound still keeps playing after StopSound is called.

This made me thought that you cannot stop looped sounds but I'm not sure. And yes, it has to be looped.
Can you show the script?
I'll give you an example.

Code:
void OnStart()
{
PlaySoundAtEntity("sound1","sound1.snt","area_sound", 0, true);
AddUseItemCallback("", "item", "area_event", "event", true);
}

void event(string &in asItem, string &in asEntity)
{
StopSound("sound1", 0.1f);
PlaySoundAtEntity("", "sound3.snt", "Player", 0, false);
PlaySoundAtEntity("sound2", "sound2.snt", "area_sound", 0, false);
PlayPropAnimation("object", "animation", 0, false, "event2");
RemoveItem("item");
}

void event2(string asProp)
{
StopSound("sound2", 0.1f);
}
Both sound1 and sound2 keep playing in my script.
Hmm, yeah that does look a little odd why they keep playing. Could you post the contents of the snt files as well?
It looks like this.

Code:
<SOUNDENTITY>
  <SOUNDS>
      <Main>
          <Sound File="sound1" />
        <Sound File="sound2" />
        <Sound File="sound3" />
        <Sound File="sound4" />
        <Sound File="sound5" />
        <Sound File="sound6" />
      </Main>
  </SOUNDS>
  <PROPERTIES Volume="0.8" MinDistance="10" MaxDistance="20" Random="1" Interval="0.05" FadeEnd="False" FadeStart="False" Stream="False" Loop="True" Use3D="True" Blockable="False" BlockVolumeMul="0.7" Priority="0" />
</SOUNDENTITY>
Not sure if it'll help, but I suggest keeping names separate, that way you don't accidentally refer to something else. So by naming the sounds something different from the internal names, it might clear up some potential issues.

Another thing you can try is naming the internal sound the same as the item you're using. Then you can use RemoveItem(asItem) and StopSound(asItem) to make sure it affects the exact reference it gets.
(03-28-2018, 04:52 PM)Mudbill Wrote: [ -> ]Not sure if it'll help, but I suggest keeping names separate, that way you don't accidentally refer to something else. So by naming the sounds something different from the internal names, it might clear up some potential issues.

Another thing you can try is naming the internal sound the same as the item you're using. Then you can use RemoveItem(asItem) and StopSound(asItem) to make sure it affects the exact reference it gets.
Actually, the internal names from the sounds are different to their file names.
RemoveItem doesn't affect sounds via script I think.
No, but it allows you to make sure the correct reference is captured by checking if your item has been removed.

From what I can see, your sounds are named sound1 with same file name + .ogg / .snt etc.
Humor me and try what I suggested. It may not do anything, but I don't really have any other suggestions right now.

If it doesn't help, perhaps package it all up and send it over and I can take a look.