Frictional Games Forum (read-only)

Full Version: Ending a Looping sound [NEED HELP]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Ok, now the title is slightly misleading, i don't ened help stopping a sound from looping as in just playing again and again (i know that is down to changing it from "1" to "0" or something, i am actually asking about something slightly different,

Please read the below mock up script; (Bear in mind it is a mock up and so this script is missing a few components that i deemed unnecessary for my example.

}
AddEntityCollideCallback("Player", "StartSoundsArea", "PlaySounds")
}

void PlaySounds(Parent, Child, State)
{
PlaySoundAtEntity("EnemyGrunting", "Player");
AddTimer( 1.5f, "PlaySounds2");
}

void PlaySounds2( Timer)
{
PlaySoundAtEntity("EnemyGrowling", "Player");
AddTimer( 1.5f, "PlaySounds3");
}

voidPlaySounds3( Timer)
{
PlaySoundAtEntity("EnemyGrunting", "Player");
AddTimer( 1.5f, "PlaySounds2");
}



Ok, so above we now have a timer that starts when i enter the area, and it plays two different sounds, one after the other, with a 1.5 second gap between each, however, I want the player to get walk across the room, being scared of these sounds, but as he reaches the far side of the room, i want them to stop, so it feels like the creature has noticed him and gone quiet. However, due to the way i am making the two sounds play one after another in a timer loop, i am not sure what function to use to cut the sounds out.

I know i will need to add another AddEntityCollideCallback at the far side of the room which will call some sort of function to break the loop of sounds, however i am not sure what function to use,

Please can somebody help me =)

Thank you =)

Edd,
Try using RemoveTimer?
(05-08-2011, 08:02 PM)Khyrpa Wrote: [ -> ]Try using RemoveTimer?

=D I will try that ^_^ Thank you =)
You could also try StopSound(string& asSoundName, float afFadeTime); in the function that is called when you reach the far end of the room.
(05-08-2011, 08:22 PM)Roenlond Wrote: [ -> ]You could also try StopSound(string& asSoundName, float afFadeTime); in the function that is called when you reach the far end of the room.

will that work? or will it simply stop the sound, skip to the timer and then continue the loop?
You have a point. You'd probably need both the stop sound function to stop the sound currently playing, as well as a remove timer function to stop any new sounds from playing Smile
(05-08-2011, 08:43 PM)Roenlond Wrote: [ -> ]You have a point. You'd probably need both the stop sound function to stop the sound currently playing, as well as a remove timer function to stop any new sounds from playing Smile

yeah =) and just put a stop sound and stop timer function for every sound and timer i use all together in the AddEntityCollideCallback function, i will test it when ir each that apart in my map making =) I am still a room or two away and the idea is still a hypotesis =) Thank you guys for you tremendous help though ^_^

I will update this thread with the imminent success =)

Edd,
Create a boolean variable for each timer, and check it's state before re-adding the timer in the callback function. You can then just set the boolean var to false when you don't want the sound to loop anymore, i.e on collision with some script area in your case.

If you want to stop the sounds as soon as this happens, couple that with a StopSound() call, and a RemoveTimer() call. However, these last two steps shouldn't really be necessary, as unless your sound is really long, it just "cutting out" will sound unnatural and perhaps break immersion - it may be better to just stop the loop, and let the sound finish it's last play using the method outlined in the first paragraph.
(05-09-2011, 12:52 AM)Apjjm Wrote: [ -> ]Create a boolean variable for each timer, and check it's state before re-adding the timer in the callback function. You can then just set the boolean var to false when you don't want the sound to loop anymore, i.e on collision with some script area in your case.

If you want to stop the sounds as soon as this happens, couple that with a StopSound() call, and a RemoveTimer() call. However, these last two steps shouldn't really be necessary, as unless your sound is really long, it just "cutting out" will sound unnatural and perhaps break immersion - it may be better to just stop the loop, and let the sound finish it's last play using the method outlined in the first paragraph.

what is the function for changing the bool value of the sound function? =)
(05-09-2011, 06:52 AM)Simpanra Wrote: [ -> ]what is the function for changing the bool value of the sound function? =)

Use "GetLocalVarInt" using 0 for false (not 0 for true). You could use a "bool x = false;" outside the function, but the status of that variable wouldn't be saved as it is with the function based approach. In the case of your code, you would do something like this:

Code:
void onStart()
{
AddEntityCollideCallback("Player", "StartSoundsArea", "PlaySounds");
SetLocalVarInt("breakSndLoop", 0);
}

void PlaySounds(Parent, Child, State)
{
PlaySoundAtEntity("EnemyGrunting", "Player");
if(GetLocalVarInt("breakSndLoop") == 0) AddTimer(1.5f, "PlaySounds2");
}

void PlaySounds2( Timer)
{
PlaySoundAtEntity("EnemyGrowling", "Player");
if(GetLocalVarInt("breakSndLoop") == 0)  AddTimer( 1.5f, "PlaySounds3");
}

void PlaySounds3( Timer)
{
PlaySoundAtEntity("EnemyGrunting", "Player");
if(GetLocalVarInt("breakSndLoop") == 0)  AddTimer( 1.5f, "PlaySounds2");
}

void StopLoop()
{
SetLocalVarInt("breakSndLoop", 1);
//If wanted, a removeTimer() and stopSound() can be used too here
//But it shouldn't be necessary - and may sound very sudden.
}
Pages: 1 2