Slider questions

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By malachi
  1. I made some sliders to adjust the volume of the various BGM and sound effects, but realized that they’re set to a linear scale, while audio works off of the logarithmic decibel scale.

Is there a way to set the audio scale to be logarithmic, or do I need to do that in the code?

  1. Every time I enter the scene with the sliders, they reset their value to what they’re set to in the Inspector menu. I want them to retain the values used when the screen was last open. I tried to pull the values from the audio buses in the _ready() function, but they get reset before entering that function.

Is there a way to either not trigger the value_changed() function when entering the tree, or to otherwise not overwrite the previous values?

Code:

func _ready():
     $SoundVolumeSlider.value = AudioServer.get_bus_volume_db((AudioServer.get_bus_index("SoundEffects")))

func _on_SoundVolumeSlider_value_changed(value):
	AudioServer.set_bus_volume_db(AudioServer.get_bus_index("SoundEffects"), $SoundVolumeSlider.value)
:bust_in_silhouette: Reply From: Shakkael

I don’t know how to help with the first question, but the second one is easy. You have to save those changes somewhere, so you should save it for example in json or any txt file and make script that:
a) saves last settings
b) retains last saved settings

It should be easy to find such tutorial

Thanks for the tip!

I also found that the functions db2linear() and linear2db() convert the values the way I want for #1 above.

malachi | 2020-06-23 03:31