Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: steptoe on Sat 21/07/2012 17:44:12

Title: Volume slider: volume issue
Post by: steptoe on Sat 21/07/2012 17:44:12
Hi

I have just noticed something that really needs putting right.

I have included a sound on/off button and a volume slider control. 

Both these work ok.

However, I now notice that if i adjust slider to say 20 and then turn sound off and then sound back on the slider stays the same but the volume is 100.

Naturally I would like the slider volume level to remain the same after sound off and then sound on.

Obviously the volume reflects in the code, so, something else is required.

Code (AGS) Select
function Bspkon_OnClick(GUIControl *control, MouseButton button)
{
  if (Bspkon.NormalGraphic==1125)
  {
 
Bspkon.NormalGraphic=1126;
System.Volume = 0;
Lsoundonoff.Text="Off";
}
else if (Bspkon.NormalGraphic==1126)
{
 
Bspkon.NormalGraphic=1125;
System.Volume = 100;
Lsoundonoff.Text="On";
}
}



Cheers for all assistance

EDIT: This seems to do the trick (at least i'm sure)

Code (AGS) Select
function Bspkon_OnClick(GUIControl *control, MouseButton button)
{
if (Bspkon.NormalGraphic==1125)
{
 
Bspkon.NormalGraphic=1126;
System.Volume = 0;
Lsoundonoff.Text="Off";
}
else if (Bspkon.NormalGraphic==1126)
{
 
Bspkon.NormalGraphic=1125;
System.Volume = 100;
Lsoundonoff.Text="On";
System.Volume = sldAudio2.Value; // ADDED THIS BIT

}
}


Title: Re: Volume slider: volume issue
Post by: monkey0506 on Sat 21/07/2012 19:15:00
Code (ags) Select
// Bspkon_OnClick
  else if (Bspkon.NormalGraphic == 1126)
  {
    Bspkon.NormalGraphic = 1125;
    System.Volume = 100;
    Lsoundonoff.Text = "On";
    System.Volume = sldAudio2.Value; // ADDED THIS BIT
  }


It's helpful to understand what your code is actually doing. Assuming that 1126 is the sprite that represents the speakers (and volume) being "on" (not muted), then you do realize that:

Code (ags) Select
System.Volume = 100;

This line is the reason it was always being set to 100 and not the current value of sldAudio2...right? For the record, that line shouldn't even exist in your amended code at all. You solved the issue by setting System.Volume to the right value, but you still shouldn't be setting it to some erroneous value immediately beforehand.
Title: Re: Volume slider: volume issue
Post by: steptoe on Sat 21/07/2012 20:05:32
Hi Monkey

Point taken. I should have realized.

Still, job done.

Thanks  (nod)

steptoe