System.Volume reset when loading a save game

Started by rongel, Fri 12/02/2021 10:32:29

Previous topic - Next topic

Crimson Wizard

#20
I hoped the above problem is solved, did not read all the thread. Just wanted to say that System.Volume definitely suppose to be a part of the saved game now. And the usual problem is opposite: that people do not want it to be because that will change the volume when they restore older saves. So they use custom config instead, as noted above in this thread.

There's definitely a historical issue of some properties of the system being in the save while it would be better if they were not. I recall in the past we have removed Gamma setting from being written in the save for this particular reason, but it was more like a quick hack, as there's more to it.


In regards to audio type volume, and having relative adjustment instead of absolute, I and other people posted this or similar advice over years on forums: do not apply slider volume to audiotype volume directly, but have a table of default volumes for your clips and pass all played clips in a loop and set their volume manually as (default volume) * (factor), where factor is from 0.0 to 1.0 and is controlled by your slider(s).
The table may work like this: you make an array of ints sized to max number of channels, and every time new clip is played you
a) take its starting volume and save in the array on corresponding slot
b) recalculate volume value using your slider positions and assign new volume using above rule.
This is more scripting work, but shall give you more control over your sound.

rongel

Quote from: Crimson Wizard on Fri 12/02/2021 22:42:57
I hoped the above problem is solved, did not read all the thread. Just wanted to say that System.Volume definitely suppose to be a part of the saved game now.

At least for me, the System.Volume is not saved with the save game. And I can't seem to load it from the config file either. It would be great if someone else could confirm this (or the opposite!). I forgot to mention that I'm using version 3.5.0.23. I'll get back to this tomorrow.
Dreams in the Witch House on Steam & GOG

Crimson Wizard

Quote from: rongel on Fri 12/02/2021 16:06:43
Code: ags
if(event == eEventRestoreGame && data !=999) {
        
   AfterLoadGame();
   Display("System.Volume is %d", System.Volume);
  }


It displays the correct value! So the game says the System.Volume is 13 for example, but I can hear everything playing at 100 value. It must mean that the config file is working, but the actual sound that is playing doesn't obey the System.Volume. If I adjust the slider, the volume jumps to correct value. Weird...

Ok, so, the values are correct, but they fail to be set to System.Volume. Other possibilities are:
- it's set, but system.volume is not applied to sounds in the engine (engine bug);
- it's set, but you have some script overriding this somewhere (script bug).

rongel

Quote from: Crimson Wizard on Fri 12/02/2021 23:02:11
Ok, so, the values are correct, but they fail to be set to System.Volume. Other possibilities are:

I didn't notice any scripts that are overriding System.Volume, but it's possible I missed something. But I got some results just now, something weird is definetely going on! If I put System.Volume =0; before the AfterLoadGame, like this:

Code: ags
if(event == eEventRestoreGame && data !=999) {
   System.Volume =0;   
   AfterLoadGame();
  }


It works! Unless I have put the slider to min value 0... Then it plays the System.Volume at 100% again. Not sure what's going on, but I got it working by giving the slider a Min Value of 1 instead of 0. In the end I have now this system, and I can restore the saved System.Value.

Code: ags
// MASTER VOLUME SLIDER
function sldMasterVolume_OnChange(GUIControl *control)
{
  System.Volume = sldMasterVolume.Value;
  system_vol = sldMasterVolume.Value;
}


Code: ags
// ON EVENT
if(event == eEventRestoreGame && data !=999) {
  System.Volume =0;
  if(system_vol !=0) System.Volume = system_vol;
}


But it's not perfect either, using the slider value of 1 instead of 0, I can't completely mute the sound...
Dreams in the Witch House on Steam & GOG

rongel

Just trying things here, and for some reason this seems to work.

Code: ags
if(event == eEventRestoreGame && data !=999) {
   System.Volume =1;   
   AfterLoadGame();
  }


The slider is again at 0-100 values, like it should be. The sound is playing at correct volume, when loading a save game. Even if I have muted the volume with the slider, it remembers that and stays muted. Using a zero works too, unless the slider is set to value 0. I can't see no other reason for this than an engine bug.
Dreams in the Witch House on Steam & GOG

Crimson Wizard

#25
I cannot tell from the script, but do you change the slider's position too when you set System.Volume? They should normally stay in sync.

Also, don't really understand what system_vol is for there.

Maybe I will find time to test this later.

rongel

QuoteI cannot tell from the script, but do you change the slider's position too when you set System.Volume? They should normally stay in sync.
No, I don't touch the slider. It's always in the correct position. Moving the slider does this: System.Volume = sldMasterVolume.Value;.

QuoteAlso, don't really understand what system_vol is for there.
Yes, it's not needed. I've tested many different approaches here. Main thing is that I couldn't change the volume unless I put System.Volume =1; before the volume loading script in eEventRestoreGame. Now that I've done that, it seems I can adjust it in many ways.
Dreams in the Witch House on Steam & GOG

Cassiebsg

On this game (Unexpected at the Rising Star) I put a lot of work on the settings and sound system (because I'm a complicated person  (laugh) ). I used a module to keep track of all those variables and such.

If you like, give it a test and see if my game has this bug or not. Though I think I tested insistently to make sure the sound system worked as I wanted.
There are those who believe that life here began out there...

rongel

Quote from: Cassiebsg on Sun 14/02/2021 22:28:15
If you like, give it a test and see if my game has this bug or not. Though I think I tested insistently to make sure the sound system worked as I wanted.

Hi! I did a quick test with your game, but I don't think your sound slider uses System.Volume? The sound slider is not a "master volume" and doesn't affect the music, or speech. So everything seems to work nicely. The issue I encountered is only with the System.Volume.
Dreams in the Witch House on Steam & GOG

Cassiebsg

#29
Ah, didn't knew that. I'm using Game.SetAudioTypeVolume.

Though, if all else fails, you can just set all these types associated  to the same slider, unless you have sliders for all these plus System.Volume. I decided to only let players set the different types of sounds, since they can control their main volume on windows itself or their speakers/headphones...

Anyway, if you want to try the module, it's IniFile by Wyz
I have set it up to load the file at game.start and on_event Restore.
There are those who believe that life here began out there...

SMF spam blocked by CleanTalk