Play a sound once

Blitz3D Forums/Blitz3D Beginners Area/Play a sound once

Chad(Posted 2008) [#1]
Hey guys, simple problem here:

If (EntityDistance(player,dude) < 5) Then PlaySound("C:\Users\User\Desktop\3d_tuts2_source-media\congrats.wav")
End If


I only want the sound to play once, right now when you the player gets to within the distance i want, the sound plays I'm guessing 100 times for every second I'm within the distance.

My question is, how can I get the sound to play just once?


Rob Farley(Posted 2008) [#2]
Take a look at the channels
Sound=LoadSound("Sound.wav")

If ChannelPlaying(SoundChannel) = False Then SoundChannel = PlaySound(Sound)

Also... You might want to use a variable
PlayCongrats = 0

.. Loop...

If EntityDistance(player,dude) < 5 Then PlayCongrats = 1
If PlayCongats  = 1
	Playsound(Sound)
	PlayCongrats = 2
End if

..End Loop..


http://www.blitzbasic.com/b3ddocs/command.php?name=sound
http://www.blitzbasic.com/b3ddocs/command.php?name=channel


Shambler(Posted 2008) [#3]
more like...

PlayCongrats=0

Loop...

If EntityDistance(player,dude) < 5  and PlayCongrats=0
        PlayCongrats = 1
	Playsound(Sound)
End if

..End Loop..



Rob Farley(Posted 2008) [#4]
That's better! I thought mine looked overly complicated! I've done stuff like that 1000 times obviously had a mind block!


Chad(Posted 2008) [#5]
It's still playin the sound infinite amount of times.

I experimented using a PauseChannel(sound) after PlaySound but it gave me a MAV.


GfK(Posted 2008) [#6]
I experimented using a PauseChannel(sound) after PlaySound but it gave me a MAV.
I think you're getting confused between sounds and sound channels - they aren't the same.


Ace Killjoy(Posted 2008) [#7]
What loop would you suggest using?


IPete2(Posted 2008) [#8]
Hi,

Actually there is a smashing library in the code arcihves which allows you to request sounds with a series of parameters on how to play the sound.

Not sure where it is but look for a function called requestsound

IPete2.