Castle Paradox Forum Index Castle Paradox

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Gamelist   Review List   Song List   All Journals   Site Stats   Search Gamelist   IRC Chat Room

Help with script for playing SFX only while key is pressed..

 
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP!
View previous topic :: View next topic  
Author Message
sheamkennedy




Joined: 06 May 2013
Posts: 23
Location: Canada

PostPosted: Thu May 23, 2013 7:27 am    Post subject: Help with script for playing SFX only while key is pressed.. Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Bob the Hamster
OHRRPGCE Developer




Joined: 22 Feb 2003
Posts: 2526
Location: Hamster Republic (Southern California Enclave)

PostPosted: Thu May 23, 2013 9:23 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
sheamkennedy




Joined: 06 May 2013
Posts: 23
Location: Canada

PostPosted: Thu Jun 06, 2013 7:08 am    Post subject: Reply with quote

Thanks, that works perfectly.
_________________
SMK
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP! All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group