[SOLVED] Audio reservation & functions (2 tiny Questions)

Hi ho there!

I’ve got 2 questions, quite small i think.

Audio Reservation - Easier way to silence other channels?

I’m using audio.reserveChannels() to reserve channel 1 for music.
The rest is for game sound effects.

I have 2 mute buttons; 1 for music and 1 for Sounds.
I have done the music one, ‘audio.setVolume(0.0, { channel=1 })’

To do the sound effects i basically have to setVolume(0.0) on all the other channels except channel 1.
Is there a way to specify all other channels or does setVolume without channel specification work on all channels that are not specified?
Or something like it?
localise functions
I have a local function that calls when the player collides, it ends the level.
Within that function i have a timer which calls another function.

I could not get that timer function to call unless i leave out the local part.
See Below for Code it’s clearer)

local function levelCompleteSensor (e)  
 if (e.phase == "began" and e.other.Col == "player") then  
 audio.play(tada);  
 timerStash.newTimer = timer.performWithDelay(1000, compStar1); -- take no notice of syntax, just a module to help deletion.  
 end  
end  
  
function compStar1() -- This wont call from the above timer unless it's function without the 'local', and outside of the above function.  
 print("Yay");  
 end  

Can anyone enlighten me a way to get that local? as it worries me :wink:

Thanks in advance,
Your loyal servant,
Me. [import]uid: 91798 topic_id: 17820 reply_id: 317820[/import]

  1. No, there isn’t a convenience function provided for what you describe. You are doing the right thing.

  2. Will defining the function compStar1 before (above) levelCompleteSensor solve the problem?
    Also, if you don’t need to reuse the function, you could declare it inline/anonymous directly in your performWithDelay call.

[import]uid: 7563 topic_id: 17820 reply_id: 68023[/import]

For #2) placing the function above the levelCompleteSensor function worked as you described.

I didn’t know you could declare it inline like you suggested, interesting to know!
Regarding #1) I just want to be sure.
To set the volume of channels 2 through 32 to 0.0.
(Leaving channel 1 volume on)

Am i going to have to type:

audio.setVolume(0.0, {
channel = 2,
channel = 3,
channel = 4,
…etc}); ?

I just tried the above method, and it doesn’t seem to have worked. I don’t know if, in the simulator, you have more channels available (because your on PC).
Or whether i have to be more tedious and do audio.setVolume for each channel.

There’s no way to type channel = 2 - 32?
or channel > 2?

Thanks ewing!
[import]uid: 91798 topic_id: 17820 reply_id: 68032[/import]

  1. Sorry, no. That won’t work. You need to call it once for each channel.

for i=2,32 do
audio.setVolume(0.0, {channel=i})
end

[import]uid: 7563 topic_id: 17820 reply_id: 68033[/import]

Yes that for loop works great…

…i was about to do that :stuck_out_tongue:

Thanks for the help there ewing. [import]uid: 91798 topic_id: 17820 reply_id: 68050[/import]