Spam sound problem - maxing out channel

Started by Tonic Ink, Sat 28/11/2009 01:39:05

Previous topic - Next topic

Tonic Ink

Hey Guys,

A quick question with I'm sure an easy fix.

I have an inventory button on my GUI, when clicked this opens the inventory window and plays a sound.

Problem with this is that if the player chooses to rapidly click the button, the sound ends up maxing out the channels and destroys the ambient track.

The fix i have implemented currently inserts a wait time after the payer clicks the button to ensure it's not clicked repeatedly. I don't like this, as it feels clunky.

THE CODE -

function btnBag_OnClick(GUIControl *control, MouseButton button)
{
if (gInventbag.Visible) gInventbag.Visible = false;
else gInventbag.Visible = true;
aSOUND3.Play();
Wait(30);

I think the code i'm looking for is something along the lines of.

if sound is playing aSOUND3 = false
play sound aSOUND3

Something along those lines. Just can't code it properly with my insufficient brain.

I can play queued, however it just banks up the sounds, obviously.

Hope that makes sense.

Cheers :)

Creator

#1
Couldn't you turn off the other GUI while your inventory is visible? Or maybe you could overlap your inventory GUI with the other GUI, thus hiding the Bag button from view.

Never mind. I see that your Bag button closes and opens the GUI. How about a timer?

Code: ags

function btnBag_OnClick(GUIControl *control, MouseButton button)
{
 if (gInventbag.Visible) {
   if (IsTimerExpired(1) == 1) {
     gInventbag.Visible = false;
   }
   else {
     return;
   }
 }
 else {
   SetTimer(1, 30);
   gInventbag.Visible = true;
   aSOUND3.Play();
 }
}

SMF spam blocked by CleanTalk