Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 2 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ending a Looping sound [NEED HELP]
Simpanra Offline
Senior Member

Posts: 314
Threads: 28
Joined: Mar 2011
Reputation: 0
#1
Ending a Looping sound [NEED HELP]

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,
(This post was last modified: 05-08-2011, 07:53 PM by Simpanra.)
05-08-2011, 07:52 PM
Find
Khyrpa Offline
Senior Member

Posts: 638
Threads: 10
Joined: Apr 2011
Reputation: 24
#2
RE: Ending a Looping sound [NEED HELP]

Try using RemoveTimer?
05-08-2011, 08:02 PM
Find
Simpanra Offline
Senior Member

Posts: 314
Threads: 28
Joined: Mar 2011
Reputation: 0
#3
RE: Ending a Looping sound [NEED HELP]

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

=D I will try that ^_^ Thank you =)
05-08-2011, 08:07 PM
Find
Roenlond Offline
Senior Member

Posts: 331
Threads: 3
Joined: Apr 2011
Reputation: 0
#4
RE: Ending a Looping sound [NEED HELP]

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
Find
Simpanra Offline
Senior Member

Posts: 314
Threads: 28
Joined: Mar 2011
Reputation: 0
#5
RE: Ending a Looping sound [NEED HELP]

(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?
05-08-2011, 08:32 PM
Find
Roenlond Offline
Senior Member

Posts: 331
Threads: 3
Joined: Apr 2011
Reputation: 0
#6
RE: Ending a Looping sound [NEED HELP]

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
Find
Simpanra Offline
Senior Member

Posts: 314
Threads: 28
Joined: Mar 2011
Reputation: 0
#7
RE: Ending a Looping sound [NEED HELP]

(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,
05-08-2011, 08:55 PM
Find
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#8
RE: Ending a Looping sound [NEED HELP]

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.
(This post was last modified: 05-09-2011, 01:16 AM by Apjjm.)
05-09-2011, 12:52 AM
Find
Simpanra Offline
Senior Member

Posts: 314
Threads: 28
Joined: Mar 2011
Reputation: 0
#9
RE: Ending a Looping sound [NEED HELP]

(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
Find
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#10
RE: Ending a Looping sound [NEED HELP]

(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:

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.
}
(This post was last modified: 05-09-2011, 09:47 AM by Apjjm.)
05-09-2011, 09:44 AM
Find




Users browsing this thread: 1 Guest(s)