Page 1 of 1

StopSound on sound effects

PostPosted: Sun Dec 04, 2005 7:41 pm
by Kodo
Is there any way to use stopSound on a sound effect (PlaySound2) without stopping other soud effects and background music. I have an elevator that operates on a switch, when the player is holding down the switch the sound repeats, when they remove the mouse from the button it should stop.

I've tried assigning the elevator sound to a channel...

elevator_sound_2 = PlaySound2("data/Mousetick1.wav", 1.000000, 99, 0.000000);

then on another event I have...

stopSound(elevator_sound_2);

this doesnt do anything.

I've tried playing the samples using PlayMusic2 as well, but when I use stopSound(elevator_sound_2) the background music also stops.


Is there some other way of turning on/off looped sound effects on events that I should be using instead? Is there only one channel that can be turned on/off?

Thanks in advance!

PostPosted: Mon Dec 05, 2005 12:05 pm
by makslane
Make sure don't change elevator_sound_2 in other place and have sufficient channels in Game Properties.


I've tried playing the samples using PlayMusic2 as well, but when I use stopSound(elevator_sound_2) the background music also stops.


You can play only one music at same time.

PostPosted: Mon Dec 05, 2005 7:25 pm
by Kodo
ok the only places there is anything to do with this sound triggering and disabling are on the one 'button' in my game. Theres nothing much else going on except some background music (MOD) and a WAV jump sound effect which doesnt play all the time anyway.

Here's how it was set up, but it doesnt work :(

( elevator_sound is Global, Real )
------------------
EVENT: On Mouse Down
------------------

if (elevator_sound_on == FALSE)
{
PlaySound2("data/Iron.wav", 1.000000, 9999, 0.000000);
elevator_sound = PlaySound2("data/Iron.wav", 1.000000, 9999, 0.000000);
elevator_sound_on = TRUE;
}


------------------
EVENT: On Mouse Up
------------------
stopSound(elevator_sound);
elevator_sound_on = FALSE;


This has no effect, when I release the mouse button the sound continues to repeat :( I realise I'm probably doing something stupid, but any help most appreciated!

PostPosted: Mon Dec 05, 2005 7:35 pm
by makslane
I can't see what is wrong.
If you can, send me the game files (use the subject "StopSound on sound effects" in email)

PostPosted: Mon Dec 05, 2005 8:09 pm
by Kodo
email sent, thanks for your help :)

PostPosted: Tue Dec 06, 2005 12:46 am
by makslane
Dr Reed wrote: PlaySound2("data/Iron.wav", 1.000000, 9999, 0.000000);
elevator_sound = PlaySound2("data/Iron.wav", 1.000000, 9999, 0.000000);


Ok, I can see the problem now.

Are you playing two sounds:

A) PlaySound2("data/Iron.wav", 1.000000, 9999, 0.000000);
B) elevator_sound = PlaySound2("data/Iron.wav", 1.000000, 9999, 0.000000);

The stopSound(elevator_sound) are stopping the play B, but can't stop the play A.
You need create other variable to hold the A channel to stop later.

PostPosted: Tue Dec 06, 2005 10:14 am
by Kodo
Doh!

I just removed PlaySound2("data/Iron.wav", 1.000000, 9999, 0.000000); and now it's working just fine!!

What it was, was that I didn’t realise that Line 'B' would actually start the sample playing, I thought you had to 'A' play the sound and 'B' assign it to a free channel, now I realise What was going on, thanks for the great support, and thanks for the emails :)