multiple sound quandary

Hi,

I am very famaliar with the sound api but I am struggling to implement something.

  1. I have a ship that fires a laser

  2. the laser has a sound

  3. I have an enemy that has an explosion sound

all pretty standard stuff so far

  1. the laser sound plays when fired

  2. when the laser hits the enemy the explosion sound plays.

Now the laser can fire radily and each one has a laser sound.

I need to stop the laser sound when it hits the enemy.

SOunds simple but no.

I have to use a channel to stop the audio i,e, audio.stop(channel number)

But when I do this it stops ALL the laser sounds in play which is no good.

I tried assigning channels in a table and then removing them through a loop in the collision code…it had varied results but not successful.

Anybody know how I can achieve this ? stop the sound of the collided lazer only.

thanks

this is what i was trying but couldnt get it working properly:

lazerSoundHandles ={} lazerSounds ={7,8,9,10,11,12,13,14,15,16,17 }   lazerSound = audio.loadSound("sounds/sfx/lazer.wav")   function fire() lazerSoundHandle = audio.play(lazerSound,{channel = lazerSounds,loops = 0})                            lazerSoundHandles[lazerSoundHandle] = lazerSoundHandle end   function lazer :collision for k, v in pairs(lazerSoundHandles) do                                           audio.stop(v) end

You could try using several defined channels (say, 1, 2, 3, and 4 - more if needed), and each time you play a laser sound, play it on the next channel using a counter (as in, 1-2-3-4-1-2-3-4). When you play the sound, store the channel it was played in and voilà! you’ve singled out a single sound, which can then be stopped apart from the others.

  • Caleb

Oh, I got it.

here is how i did it in some scratched up code with the important bits:

  function createlazer()   lazer.channel = audio.findFreeChannel() lazer.audio = audio.play(lazerSound,{channel = lazer.channel, loops = 0})   end   function lazer:collision()   audio.stop(target.channel) end

You could try using several defined channels (say, 1, 2, 3, and 4 - more if needed), and each time you play a laser sound, play it on the next channel using a counter (as in, 1-2-3-4-1-2-3-4). When you play the sound, store the channel it was played in and voilà! you’ve singled out a single sound, which can then be stopped apart from the others.

  • Caleb

Oh, I got it.

here is how i did it in some scratched up code with the important bits:

  function createlazer()   lazer.channel = audio.findFreeChannel() lazer.audio = audio.play(lazerSound,{channel = lazer.channel, loops = 0})   end   function lazer:collision()   audio.stop(target.channel) end