Play a sound once

Blitz3D Forums/Blitz3D Beginners Area/Play a sound once

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?

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

more like...

PlayCongrats=0

Loop...

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

..End Loop..


That's better! I thought mine looked overly complicated! I've done stuff like that 1000 times obviously had a mind block!

It's still playin the sound infinite amount of times.

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

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.

What loop would you suggest using?

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.