Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Ultra Magnus on Mon 09/02/2009 15:26:53

Title: Reading volume values [SOLVED]
Post by: Ultra Magnus on Mon 09/02/2009 15:26:53
Hello people.
I couldn't find the answer to this anywhere, so...

How can I get the game to read and store the user-set volume levels for music and sound?
Here's what I've got now...

After tooling around with the sliders, the player clicks either btnResume to save their changes and resume playing, or btnNoChange to discard the changes they made and go back to the last saved set of values.

function btnResume_OnClick(GUIControl *control, MouseButton button)
{
  lastMsldval=sldMusic.Value;
  lastMlevel=
  lastSsldval=sldSound.Value;
  lastSlevel=
  lastGsldval=sldGamma.Value;
  lastGlevel=System.Gamma;
}

function btnNoChange_OnClick(GUIControl *control, MouseButton button)
{
  sldMusic.Value=lastMsldval;
  SetMusicMasterVolume(lastMlevel);
  sldSound.Value=lastSsldval;
  SetSoundVolume(lastSlevel);
  sldGamma.Value=lastGsldval;
  System.Gamma=lastGlevel;
}


What can I fill btnResume's gaps with?

Thanks in advance.
J.
Title: Re: Reading volume values
Post by: Pumaman on Tue 10/02/2009 00:31:47
Why have you got two variables for each thing, like lastMsldval and lastMlevel? What is each one supposed to represent?
Title: Re: Reading volume values
Post by: Khris on Tue 10/02/2009 03:47:18
Yes, one variable per setting is enough (if it weren't possible to cancel, you'd need no additional vars; adding this possibility adds the need for one additional variable per setting.)
I believe Ultra Magnus thought he'd need two because one can't read e.g. the current MusicMasterVolume.

Ultra Magnus:
Say the music volume is 70 at the start of the game. lastMlevel, sldMusic.Value and the game's MusicMasterVolume are all set to 70.
Now the player opens the settings GUI, then slides the slider to 80. This changes the actual volume to 80, so both sldMusic.Value and MusicMasterVolume are 80 now.

Resume:
-Set lastMlevel to sldMusic.Value
-exit

Cancel:
-Set sldMusic.Value and MusicMasterVolume to lastMlevel

So the functions are supposed to look like this:

function btnResume_OnClick(GUIControl *control, MouseButton button)
{
  lastMlevel=sldMusic.Value;
  lastSlevel=sldSound.Value;
  lastGlevel=sldGamma.Value;
}

function btnNoChange_OnClick(GUIControl *control, MouseButton button)
{
  sldMusic.Value=lastMlevel;
  SetMusicMasterVolume(lastMlevel);
  sldSound.Value=lastSlevel;
  SetSoundVolume(lastSlevel);
  sldGamma.Value=lastGlevel;
  System.Gamma=lastGlevel;
}
Title: Re: Reading volume values
Post by: Ultra Magnus on Tue 10/02/2009 07:46:07
The level variables were for the actual levels and the sldvals were the sliders' values (positions).
I had them both because at first I tried just this...

function btnNoChange_OnClick(GUIControl *control, MouseButton button)
{
  sldMusic.Value=lastMlevel;
  sldSound.Value=lastSlevel;
  sldGamma.Value=lastGlevel;
}


...assuming the sliders were kinda hard-wired to the levels, so they'd change together.
When clicking it made the sliders move, but the levels stayed the same, I thought I'd need to set them both separately.

I wouldn't have thought that it would be possible to read from a variable that was only just set within the same function, but Khris' suggestion works perfectly.

Thanks a lot.