need some sound help

Blitz3D Forums/Blitz3D Beginners Area/need some sound help

stayne(Posted 2003) [#1]
I'm working on an FPS, mostly just for learning, and I really need some help. I want to have a walking sound when my character moves (of course). I'm just using one .wav file at the moment. When I assign the playsound command to the keydown command, the sound continuously plays lightning fast and doesn't "loop". Loopsound doesn't work either because I see that regardless of the two, the sound just keeps starting over and over as long as the key is pressed. I tried using millisecs but it pauses the entire game.

Please someone shed some light on my little problem :)


Tricky(Posted 2003) [#2]
The code here is untested and I may have forgotten a few parameters, but it's to give the idea how to work this out...
I removed all unnessesary lines like the lines in which you load the sound and such, it's just to solve the problem you have


Global OldTimer = MilliSecs()
Global NewTimer = MilliSecs()

Repeat 
NewTimer = MilliSecs()
If KeyDown(200) And (NewTimer-OldTmer>2000) THen
   PlaySound SoundBufferVar
   OldTImer = NewTimer
   EndIf
Until Keyhit(1)



This silly routine will make the step sound every two seconds, you can make it faster or slower by adepting the 2000 in this code...

The steps are only made as long as the up key is hold down, and will stop as soon as it's released...

As I said this code is untested, it's more to give a general idea on how to solve this...


stayne(Posted 2003) [#3]
Thank you. I tried this code and got the same result, really fast stuttering. Maybe the line that I use to load the sound is wrong? Here's what I have...

Global walk1=LoadSound("step1.wav")

Using your code, I did this (i'm using the W key instead of the up arrow):

If KeyDown(17) And (NewTimer-OldTmer>2000) Then
NewTimer = MilliSecs()
PlaySound walk1
OldTImer = NewTimer
EndIf


stayne(Posted 2003) [#4]
k i fixed the spelling errors, still not working.


keyboard(Posted 2003) [#5]
this plays a sound every two seconds

Graphics 800,600
Global YourSound = LoadSound("YOUR SOUND HERE")
Global SoundPlayed = False
Global Timer# = 0
While Not KeyHit(1)
	Text 400,300,"playing a sound"	
	If SoundPlayed = False Then
		PlaySound YourSound	
		SoundPlayed = True
		Timer# = MilliSecs()			
	EndIf
	If Timer# + 2000 < MilliSecs() Then SoundPlayed = False	
Flip	
Wend
FreeSound YourSound
End



stayne(Posted 2003) [#6]
i received some help from a different forum before i saw your reply keyboard. the following code worked like a charm.

if keydown(blah)
if timer1+2000<millisecs() ;ignore it for now
timer1=millisecs() ;set the timer to millisecs
playsound run
endif
endif

thank you all for your help, it is very much appreciated. good luck coding, i'm sure i'll be asking for more ideas along the way on my little journey to a finished game.