Ren'Py Setting Default Volume

Harkonnan

Give me chiisana oppai!
Game Developer
Oct 24, 2020
190
329
I'm trying to put music in my game and I know some audio tracks are louder than others. I need to set a default volume. I looked at the documentation and it says this.

renpy.music.set_volume(volume, delay=0, channel=u'music')
Sets the volume of this channel, as a fraction of the volume of the mixer controlling the channel.

volume This is a number between 0.0 and 1.0, and is interpreted as a fraction of the mixer volume for the channel
so I used this:

renpy.music.set_volume

Then I tried putting my volume setting after it which in this case was 0.6

I tried using 0.6, =0.6, ="0.6" and (0.6)

all of which returned an error with a red arrow pointing either left or right.

If someone has experience with this please advise.

Thanks in advance.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,581
2,219
I'd highly recommend NOT setting the volume per track, since you'll be overriding whatever levels the players has picked.
You're effectively telling the player "Yeah, I know you set the volume to <x>, but I don't care and I'm setting it to <y>".

For example, I have a file I put into each game's folder before I start playing it which sets various defaults for me - including my preferred music and sound volumes. If the game suddenly changed the volume on me, I'd probably either quit the game completely or edit it to remove every single volume alteration.

But setting the default volume is possible (and something my little script file already does).
The lines you want would look something like...

Python:
init 990 python:
    config.default_music_volume = 0.15
    config.default_sfx_volume = 0.5

Now... that's only the defaults. The values are copied to the preferences values when the game start the first time.
After that, the player can alter them later any time they like.

What I think you need to be doing though... is normalizing the volume for all your music tracks to be the same levels.
Which probably means grabbing a utility like . Adobe Audition would be the paid big brother alternative.

Normalize the audio volume for peak volume. (All tracks will be equally loud at their loudest points).
Then reduce the volume for any tracks you feel are too loud compared with the rest (normalization can be quirky sometimes).

Now all your tracks should be roughly the same volume to your ear. (There's a decibel meter in most editors anyway... plus analysis tools, etc.)
Fire up your game and play a track. When you've figured out the level that sounds best to you, go set the config.default_music_volume to be roughly the same. (For me, I like the music to be quietly playing in the background rather than a distraction - hence the 15%).

I can't tell you the exact Audacity commands/menus - as I use a different tool to do the same thing.
 

Harkonnan

Give me chiisana oppai!
Game Developer
Oct 24, 2020
190
329
But setting the default volume is possible (and something my little script file already does).
The lines you want would look something like...

Python:
init 990 python:
    config.default_music_volume = 0.15
    config.default_sfx_volume = 0.5

Now... that's only the defaults. The values are copied to the preferences values when the game start the first time.
After that, the player can alter them later any time they like.
I tried plugging in this script but it didn't work for me. Is there a particular place for it?

I didn't get any errors it just didn't do anything.

I deleted the persistent save data in the appdata folder to make sure it counted as a first launch and still all volumes were at max when I lunched the game and even after hitting start the sliders were still all the way to the right.

And I will look into normalizing the music. Thanks for that suggestion.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,581
2,219
I tried plugging in this script but it didn't work for me. Is there a particular place for it?

Pretty much anywhere. Though options.rpy would be the place I'd put it if it were my game.
The init 990 python is pretty high priority (the default init python runs at 0). Though in theory a script with 991 thru 999 would override even these overrides. I only put it that high because I was using an external script file that is intended to work with any game. In your own game, it would be fine to include it in one of the existing init python sections.

In fact, if it were to go in options.rpy, I'd probably use define, like all the other options in there.
Python:
define config.default_music_volume = 0.15
define config.default_sfx_volume = 0.5

I deleted the persistent save data in the appdata folder to make sure it counted as a first launch and still all volumes were at max when I lunched the game

Keep in mind that the /appdata/ folder is only a shared copy of the game's persistent and save data.
The original sits in /game/saves/.

If you want to be sure it's really reset, a much better way is to click the [Delete Persistent] button within the RenPy launcher/SDK. It's in the first column near the bottom, just above [Force Recompile]. I'm guessing that's why you didn't see any change.

And yeah... volume normalization is the real answer to your problem.
 
  • Like
Reactions: UnderTheStairs

Harkonnan

Give me chiisana oppai!
Game Developer
Oct 24, 2020
190
329
Didn't think to use delete persistent. Once I did that the script worked fine. Thanks for the help and all the advice.

Edit:

Just wanted to let you know I followed all the advice here. I got audacity and did the volume normalizing and then set the default volumes and now everything is exactly as I wanted. Thank you to everyone who helped me.
 
Last edited:

hakarlman

Engaged Member
Jul 30, 2017
2,097
3,274
Can you guys explain precisely how to get this working? I tried

Code:
init 990 python:
    config.default_music_volume = 0.15
    config.default_sfx_volume = 0.5
But the volumes still start at 100% in game.

I also tried putting this into the options.rpy, but the volumes all are maxed out in preferences.
Code:
#option.rpy
define config.default_music_volume = 0.67
define config.default_sfx_volume = 0.67
define config.default_voice_volume = 0.67
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,581
2,219
I also tried putting this into the options.rpy, but the volumes all are maxed out in preferences.

Edit: I just noticed, I already wrote most of this already further up the thread. I'm not sure why RenPy would not use your settings as long as you cleared the persistent file(s).
Edit2: Bahh. I'm confusing hakarlman with Harkonnan .

Those lines work by setting the default values for the sound-fx and music volumes, but they only apply for the very first time you run the game. Every time after that, the values from the previous game session are used (i.e. the settings remain at whatever the player has set them to).

If you want to test it working, you need to delete the persistent data - to reset everything.

If it's a game you are developing... then just go into the RenPy launcher, select your project and click the [Delete Persistent] button near the bottom middle of the launcher window.

If it's a game that you've downloaded and played before, you need to delete the persistent file from BOTH save game locations. ./game/saves/persistent and C:\Users\username\AppData\Roaming\RenPy\game-id\peristent... where "username" is your Windows user name and "game-id" is the unique identifier for the game (usually the game's name without spaces and a bunch of seemingly random numbers).

Note that deleting the persistent file from both locations will reset more than just the default volumes.

But yeah, new users who've started the game for the first time will pick up the those settings as their defaults.

You don't have permission to view the spoiler content. Log in or register now.
 
Last edited:
  • Like
Reactions: hakarlman

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,364
15,281
If you want to test it working, you need to delete the persistent data - to reset everything.
It's just a thought and I don't really have the time to look further, but shouldn't a mix with preferences.set_volume and theafter_load label permit to avoid deleting the persistent file, with all it imply ?
Something that would looks like:
Code:
label after_load:
    $ preferences.set_volume( "music", 0.15 )
    $ preferences.set_volume( "sfx", 0.15 )
    $ preferences.set_volume( "voice", 0.15 )
    return
Note: As it, there's risk of conflict if the game already use the after_load label.

After, the problem is that it would reset your own changes on the music. But that can be solved, either by using the script only once, or by defining an unique flag to define if the volumes already have been changed or not.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,581
2,219
It's just a thought and I don't really have the time to look further, but shouldn't a mix with preferences.set_volume and theafter_load label permit to avoid deleting the persistent file, with all it imply ?

Yeah. My concern would be that an inexperienced dev might see something like after_load and mistake it for a permanent solution.

My experience here on the forums is that, sometimes, people (myself included) will just read part of an answer and pick out the bit they like and ignore all the warnings and explanations around it. So I get wary about suggesting temporary solutions that could impact the eventual players of the game.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,364
15,281
My experience here on the forums is that, sometimes, people (myself included) will just read part of an answer and pick out the bit they like and ignore all the warnings and explanations around it. So I get wary about suggesting temporary solutions that could impact the eventual players of the game.
You're more on the mama side, while I'm more on the papa one ; let's do this and hope the house don't get on fire. What isn't a criticism, I hope you know it.

It's not that I don't care, but I probably care a little less than you. Probably because I know that if there's a problem, most of the time the person who'll fix it will be you or myself. If I was writing on a blog, by example, I would probably be as cautious as you, or make the warnings more obvious, because there would have no afterward support.
 
  • Like
Reactions: 79flavors