Setting Default Volume for Custom Music Channel

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
SwashbucklerXX
Newbie
Posts: 18
Joined: Tue Sep 03, 2019 6:37 pm
Projects: Made Marion: A Robin Hood Romance
Contact:

Setting Default Volume for Custom Music Channel

#1 Post by SwashbucklerXX »

I'm trying to set a nice, comfy music/sound mix for players starting up my game. I have music, sound effects, and a custom "ambience" channel set up. The channel name is ambience and the mixer name is amb.

For music and sfx I can set default values just fine with:

Code: Select all

define config.default_music_volume = 0.75
define config.default_sfx_volume = 0.95
But when I try to do:

Code: Select all

define config.default_amb_volume = 0.5
I get a crash and:
I'm sorry, but an uncaught exception occurred.

While running game code:
File "game/options.rpy", line 71, in script
define config.default_amb_volume = 0.5
File "game/options.rpy", line 71, in script
define config.default_amb_volume = 0.5
File "renpy/common/000namespaces.rpy", line 11, in set
setattr(self.nso, name, value)
Exception: config.default_amb_volume is not a known configuration variable.
My ambience channel is properly set up, works, and has a working slider, so that's not the problem.

I assume this means that I need to use a different method to set a default volume for a custom audio channel, but what method should I use?

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2437
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Setting Default Volume for Custom Music Channel

#2 Post by Ocelot »

Your amb mixer is not something inherent to RenPy, and it knows nothing about it. There are no configuration variable tied to your mixer. You need to set volume yourself after you define your channel.
< < insert Rick Cook quote here > >

User avatar
SwashbucklerXX
Newbie
Posts: 18
Joined: Tue Sep 03, 2019 6:37 pm
Projects: Made Marion: A Robin Hood Romance
Contact:

Re: Setting Default Volume for Custom Music Channel

#3 Post by SwashbucklerXX »

Ocelot wrote: Tue Jun 01, 2021 5:36 am Your amb mixer is not something inherent to RenPy, and it knows nothing about it. There are no configuration variable tied to your mixer. You need to set volume yourself after you define your channel.
Yes. I'm asking how to do the equivalent of setting a normal variable default, but for mixer volume. I suppose I could just manually set the volume at the beginning of my script, but that seems inelegant.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2437
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Setting Default Volume for Custom Music Channel

#4 Post by Ocelot »

SwashbucklerXX wrote: Tue Jun 01, 2021 1:56 pm
Ocelot wrote: Tue Jun 01, 2021 5:36 am Your amb mixer is not something inherent to RenPy, and it knows nothing about it. There are no configuration variable tied to your mixer. You need to set volume yourself after you define your channel.
Yes. I'm asking how to do the equivalent of setting a normal variable default, but for mixer volume. I suppose I could just manually set the volume at the beginning of my script, but that seems inelegant.
This is literally what RenPy does: as long as default preferences weren't initialized, set them to values of predefined variables and set up the flag.

Code: Select all

# 00defaults.rpy
init 1500 python hide:
    if not persistent._set_preferences:
        persistent._set_preferences = True
        # ... skipped ...
        _preferences.set_volume('music', config.default_music_volume)
        _preferences.set_volume('sfx', config.default_sfx_volume)
        _preferences.set_volume('voice', config.default_voice_volume)
< < insert Rick Cook quote here > >

User avatar
SwashbucklerXX
Newbie
Posts: 18
Joined: Tue Sep 03, 2019 6:37 pm
Projects: Made Marion: A Robin Hood Romance
Contact:

Re: Setting Default Volume for Custom Music Channel

#5 Post by SwashbucklerXX »

Let me see if I can better articulate what I'm looking for. I am new at programming and don't speak the "language" very well even if I understand what's going on.

I have the default volume for Ren'py's native audio channels set in my options.rpy file. Music and sound are groovy and good to go.
I have the default values for other persistent variables found on my preferences screen (such as my explicit text vs. fade to black option for love scenes) set up like you set up defaults for any variable, aka:

Code: Select all

default persistent.explicit_text = True
I'm looking for a line of example code. I know I cannot set my default ambience volume the same way that I set default volumes for the built-in music channels. I want to code a default setting for the ambience slider in preferences, but I want to make sure that if the user changes the slider, their setting becomes persistent and isn't overwritten by my default upon game reload. I'm just looking for how I would properly code that, with a specific example of the proper syntax. It feels to me that it's something I should set as some kind of default persistent variable, but I could certainly be wrong.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2437
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Setting Default Volume for Custom Music Channel

#6 Post by Ocelot »

You can do the same way RenPy already does:

Code: Select all

init python:
    # Check if we already initialized preferences
    if not persistent.initialized:
        # Mark first-time initialization done
        persistent.initialized = True
        # Set volume preference if this is first launch
        preferences.set_volume("amb", 0.7)
        # Setup other default preferences if needed
< < insert Rick Cook quote here > >

User avatar
SwashbucklerXX
Newbie
Posts: 18
Joined: Tue Sep 03, 2019 6:37 pm
Projects: Made Marion: A Robin Hood Romance
Contact:

Re: Setting Default Volume for Custom Music Channel

#7 Post by SwashbucklerXX »

Thank you, that's what I was looking for!

Post Reply

Who is online

Users browsing this forum: Google [Bot]