View previous topic :: View next topic |
Author |
Message |
sheamkennedy

Joined: 06 May 2013 Posts: 23 Location: Canada
|
Posted: Thu May 23, 2013 7:27 am Post subject: Help with script for playing SFX only while key is pressed.. |
|
|
I followed a tutorial for making my character 'run' in my game. I also want a 'running sound' to play as a loop only while my character is running (ie. the 'z' key is being pressed). Is there a way to make a sound continuously play while I hold the 'z' key but finish playing the instant I stop holding said key?
I've got the sound to play but so far my script causes the sound to end once it has played once through.
Thanks for the help,
Shea Kennedy _________________ SMK |
|
Back to top |
|
 |
Bob the Hamster OHRRPGCE Developer

Joined: 22 Feb 2003 Posts: 2526 Location: Hamster Republic (Southern California Enclave)
|
Posted: Thu May 23, 2013 9:23 am Post subject: |
|
|
Hmmm... If I was trying to do this in my own game, I think I would use an each-step script.
Code: |
plotscript, each step sound effect, begin
if(get hero speed(me) >> 4) then(
play sound(5)
)
end
|
This assumes that a single instance of the sound takes about the same time as a running step.
I like this method because it is very simple, but the downside is that it plays the sound as you complete each step, rather than as you begin each step, so it might not sound right if you move one step and then stop immediately instead of really running.
Here is another slightly more complicated method which uses the "loop" argument of the "play sound" command to start the effect looping.
Code: |
plotscript, each step sound effect, begin
if(get hero speed(me) >> 4) then(
if(not(sound is playing(5))) then(
play sound(5,true)
)
)else(
if(sound is playing(5)) then(
stop sound(5)
)
)
end
|
Although this method is more complex, it is nice because it gives you more control. It doesn't matter if the sound effect does not match up exactly with the length of time it takes to run a step. You could also integrate this method into a "on keypress" script instead of an "each step" script if you want the sound effect to play as soon as you start moving, and stop as soon as you release the run key. |
|
Back to top |
|
 |
sheamkennedy

Joined: 06 May 2013 Posts: 23 Location: Canada
|
Posted: Thu Jun 06, 2013 7:08 am Post subject: |
|
|
Thanks, that works perfectly. _________________ SMK |
|
Back to top |
|
 |
|