Reading volume values [SOLVED]

Started by Ultra Magnus, Mon 09/02/2009 15:26:53

Previous topic - Next topic

Ultra Magnus

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.

Code: ags
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.
I don't mean to sound bitter, cold, or cruel, but I am, so that's how it comes out.

I'm tired of pretending I'm not bitchin', a total frickin' rock star from Mars.

Pumaman

Why have you got two variables for each thing, like lastMsldval and lastMlevel? What is each one supposed to represent?

Khris

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:

Code: ags
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;
}

Ultra Magnus

#3
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...

Code: ags
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.
I don't mean to sound bitter, cold, or cruel, but I am, so that's how it comes out.

I'm tired of pretending I'm not bitchin', a total frickin' rock star from Mars.

SMF spam blocked by CleanTalk