Godot Version
godot version 4.3
Question
`My mute button works but my sliders do not, i have a music and an sfx bus
extends Control
@onready var SFX_Bus_ID = AudioServer.get_bus_index("SFX")
@onready var Music_Bus_ID = AudioServer.get_bus_index("Music")
@onready var Close_Menu = %Close_Menu
func _on_music_slider_value_changed(value: float) -> void:
AudioServer.set_bus_volume_db(Music_Bus_ID, value)
func _on_sfx_slider_value_changed(value: float) -> void:
AudioServer.set_bus_volume_db(SFX_Bus_ID, value)
func _on_close_menu_pressed() -> void:
Close_Menu.play(0.0)
%Options_Menu.visible = false
func _on_mute_button_toggled(toggled_on: bool) -> void:
# Mute or unmute both SFX and Music buses based on the button state
AudioServer.set_bus_mute(SFX_Bus_ID, toggled_on)
AudioServer.set_bus_mute(Music_Bus_ID, toggled_on)
can anyone help and maybe explain it in an easy way? This is my first game so i’m not super experienced with godot or the code.
What do you mean exactly by not working?
I’m going to assume it’s because of the decibel scale .
You can use the global methods linear_to_db
and db_to_linear
to convert your slider value correctly.
Global scope constants and functions. Description: A list of global scope enumerated constants and built-in functions. This is all that resides in the globals, constants regarding error codes, keyc...
1 Like
I mean that the sliders do nothing, the volume does not change. However the mute button works perfectly.
extends Control
@onready var SFX_Bus_ID = AudioServer.get_bus_index("SFX")
@onready var Music_Bus_ID = AudioServer.get_bus_index("Music")
@onready var Close_Menu = %Close_Menu
func _ready() -> void:
$Options_Box/Music_Slider.value = db_to_linear(AudioServer.get_bus_volume_db(Music_Bus_ID))
$Options_Box/SFX_Slider.value = db_to_linear(AudioServer.get_bus_volume_db(SFX_Bus_ID))
func _on_music_slider_value_changed(value: float) -> void:
AudioServer.set_bus_volume_db(Music_Bus_ID, linear_to_db(value))
func _on_sfx_slider_value_changed(value: float) -> void:
AudioServer.set_bus_volume_db(SFX_Bus_ID, linear_to_db(value))
func _on_close_menu_pressed() -> void:
Close_Menu.play(0.0)
%Options_Menu.visible = false
func _on_mute_button_toggled(toggled_on: bool) -> void:
AudioServer.set_bus_mute(SFX_Bus_ID, toggled_on)
AudioServer.set_bus_mute(Music_Bus_ID, toggled_on)
implemented your fix but it still does not change the volume of my sliders
Oh dear! You’ll have to debug to see where the issue is.
I’d try adding printt("value", value, "db", linear_to_db(value))
to the _on_music_slider_value_changed
and _on_sfx_slider_value_changed
methods.
This will make sure they are being called and what values you are actually getting. I don’t know how a linear scale gets translated to db scale, so maybe the value is changing but it isn’t making a noticeable difference to the volume?
You can also try printing out the value from the AudioServer
before and after setting.