#Audio Sliders
48 messages · Page 1 of 1 (latest)
I think bus indexes arent 0123 theyre some random number so you have to get them by code
Create bus_index and bus_name variable for each audioserver and in ready function set each bus index by the bus name and finally instead of putting 0 1 2 you put the matching bus index
Here's the right way to let the user adjust the volume of different types of audio in your game.
Sample project: https://github.com/theshaggydev/the-shaggy-dev-projects/tree/main/projects/godot-4/volume-sliders
Text version: https://shaggydev.com/2023/05/22/volume-sliders/
Further reading
Hmmm I tried it and it still doesn't work
These are the error output when i changed the slider values while debugging
And this is my bus channels
You definitely have the bus_name variable set properly on the nodes?
I believe it would be case sensitive, so it's worth checking
Omg I did not
TT
Okay it works now but my question is that i essentially have to have 1 script for 1 slider?
I assume what's happened here is you've asked for the index of a bus name that doesn't exist, so it's returned -1, so when you try to set the value on the bus, it errors, because -1 isn't a valid index
This setup shouldn't require you to make more than just this one script
You can just use this script but change the bus_name variable for each slider
But the script has to extend HSlider?
Because I would prefer to put them in my settings_menu.gd instead of a seperate script that contains the audio code
It only needs the value_changed signal, right?
Like in here
yea i tried this yesterday but it doesn't quite work
Maybe because you weren't using linear_to_db?
hmmm Okay i'll try that again and hopefully it works
It is not safe to assume that my bus channels will have index 0, 1 and 2?
I don't know where the other person got the idea that it wasn't from
The indexes start at 0
Okay i will try my prev method again if not i'll just make it a seperate script for now
thanks alot for the explaination!
Well, okay, let me actually back up this claim by checking in the engine real quick
I did some print statements in my code and it showed 0, 1 and 2
so i was just wondering if there was actually a case where what the other person said was true
It shouldn't ever be true
I did some testing to confirm
Buses are stored in an array, I would assume
If you try to add a bus at a position beyond the size of that array, it just gets added to the end instead
Okay understood
I tried this again in my settings_menu.gd
But it still doesn't work
And i can't really call this
print(bus_index);
value_changed.connect(_on_value_changed)
value = db_to_linear(
AudioServer.get_bus_volume_db(bus_index)
)```
In my settings_menu.gd because apparently value_changed is not declared
Those on_value_changed functions.. Are they actually connected to the signals?
Also, these functions aren't changing anything right now because you're overriding the value given by the slider with the current value of the bus volume, and then putting the current value back in to the bus volume
Yes i believe so
Since this script isn't being attached to arbitrary nodes, you can just connect the signals in the editor, and normally that would show up as a little green arrow symbol next to the functions
Yep it is showing the green arrows on the left
Yea cause i was at a different scene on the tab
Anyway, these functions aren't doing anything because of this. Get rid of the value = ... lines from those functions and it should work?