How can I add my sound settings to my Global.gd autoload script?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Amateur.game.dev.

I’m trying to make my sound settings stay there when I change scenes but nothing I try works. Here is the script for the sound settings:

func _on_MasterSlider_value_changed(value):
    AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Master"),value)


func _on_MusicSlider_value_changed(value):
    AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Music"),value)


func _on_SfxSlider_value_changed(value):
    AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Sound"),value)

What is the goal here? What exactly changes, and what stays the same?

Ertain | 2021-09-12 04:40

So when the hslider is moved, the value the hslider has been changed to also makes the decibel level on the selected audio bus change. For instance, when you move the sfxslider from right to left it mutes the sfx because it is -24db. I want to find a way for the change on the hslider to affect a singleton script so that the setting stays the same in every scene.

Amateur.game.dev. | 2021-09-12 12:56

Have you tried something like the following?

func _on_MasterSlider_value_changed(value):
    settings_singleton.set_master_bus_volume_value(value)
    AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Master"),value)

If the audio settings aren’t applied in other scenes, have them set on load:

# In the scene that requires changing the audio.
func _ready():
    AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Master"), settings_singleton.get_master_bus_volume_value())

Ertain | 2021-09-13 08:06