How to make a sound effect play over itself

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

Post Reply
User avatar
Gigglyardo
Slime
Posts: 9
Joined: Sun Aug 16, 2015 1:20 am

How to make a sound effect play over itself

Post by Gigglyardo »

So basically I'm tryna make an "on keypress" script that plays a sound. I've got this:

Code: Select all

plotscript, testsound, begin
if (key is pressed (key:shift)) then (
play sound (6))
end
The problem is that, when shift is held down, the sound only plays once, then after the sound is done playing, it starts over again. I want the sound to play over itself for every tick that shift is held down.

Is this even possible? plz
User avatar
FnrrfYgmSchnish
Metal Slime
Posts: 741
Joined: Thu Jun 18, 2009 4:37 am
Location: Middle of Nowhere

Post by FnrrfYgmSchnish »

Hmm... maybe if you have the sound imported in multiple slots and have the script set up to play the second, third, etc. if the first(/second, etc.) copy of the sound is currently playing? I know I remember a "sound is playing" command, anyway, though I can't recall if I've used it for anything so I'm not sure this will work.
FYS:AHS -- Working on Yagziknian NPC walkabout sprites
User avatar
Gizmog
Metal King Slime
Posts: 2622
Joined: Tue Feb 19, 2008 5:41 am

Re: How to make a sound effect play over itself

Post by Gizmog »

Gigglyardo wrote:So basically I'm tryna make an "on keypress" script that plays a sound. I've got this:

Code: Select all

plotscript, testsound, begin
if (key is pressed (key:shift)) then (
play sound (6))
end
The problem is that, when shift is held down, the sound only plays once, then after the sound is done playing, it starts over again. I want the sound to play over itself for every tick that shift is held down.

Is this even possible? plz
Have you already tried the optional arguments defined in the plotscripting dictionary? I think that

Code: Select all

playsound (6,false,true)
Might do what you want? If it doesn't, I've used Fnrrf's multiple copies of the sound trick and it usually works pretty good. You'd want to use SoundIsPlaying like he said to check if Sound6 is already playing and play Sound7 instead, and if Sound 7 is playing play 8, and so on until you have a satisfying amount of overlap.
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

The "preempt" argument doesn't allow playing a sound multiple times at once.
You will unfortunately need to import multiple copies of the sound effect.
This is something I would like to change at some point, but it's not a high priority.
Post Reply