Changing music and sound volume simultaneously

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
rinrin
Veteran
Posts: 211
Joined: Thu Apr 16, 2009 9:18 am
Completed: Several.
Projects: Several.
Contact:

Changing music and sound volume simultaneously

#1 Post by rinrin »

I have a volume bar permanently displayed on the screen as part of the interface to make it more convenient for the player to change the volume at any time without having to go to the preference screen.
volume.png
volume.png (13.44 KiB) Viewed 684 times

Code: Select all

bar value Preference("music volume") range (80) xmaximum 80 ymaximum 10 thumb "soundbarthumb" thumb_shadow None thumb_offset 5 left_bar "soundbar_full" right_bar "soundbar_empty" 
The problem is, it works for either only music or only sound effects and I want the player to be able to change the overall volume of the game (anything that makes a sound) with this slider (those who want more precise control could still access music and sound effects separately from the preferences screen).

Is there a way to have 'Music Volume' and 'Sound Volume' controlled by the same slider (setting two values to one bar)? Or is there some kind of an overall 'Volume' preference that affects all channels? Or some other method to achieve this?
Last edited by rinrin on Thu Jun 28, 2012 6:42 am, edited 2 times in total.

User avatar
Showsni
Miko-Class Veteran
Posts: 563
Joined: Tue Jul 24, 2007 12:58 pm
Contact:

Re: Changing music and sound volume simultaniously

#2 Post by Showsni »

Hm. I have no real experience, but I guess you'd need to make your own adjustment. Here, let's try this...

In an init python block:

Code: Select all

init:
    python:
        def allvols(x):
            _preferences.set_volume("sfx", x)
            _preferences.set_volume("voice", x)
            _preferences.set_volume("music", x)
        allvolsad = ui.adjustment(range = 1.0, value = 1.0, changed=allvols)    
Then for your bar (in screen language):

Code: Select all

bar value 1.0 range 1.0 adjustment allvolsad
Does that work? If I'm right, it should tie the music, sound effect and voice volume to the same bar.

User avatar
rinrin
Veteran
Posts: 211
Joined: Thu Apr 16, 2009 9:18 am
Completed: Several.
Projects: Several.
Contact:

Re: Changing music and sound volume simultaniously

#3 Post by rinrin »

Yes, it works!
Thank you!

User avatar
rinrin
Veteran
Posts: 211
Joined: Thu Apr 16, 2009 9:18 am
Completed: Several.
Projects: Several.
Contact:

Re: Changing music and sound volume simultaneously [solved]

#4 Post by rinrin »

Update:
A strange bug occurs from time to time ever since I implemented that code. I can't reproduce it every time and have no idea what triggers it, so I'll just describe it: sometimes when I start the game, the volume bar (the one on the picture in the first post) is set to maximum, but no sound can be heard. If I move it a bit to the left, sound "activates" and works normally (doesn't stop if I pull the slider back to maximum).

It happened at least 3 times so far (not in the same session).

Does anyone have an idea what could be causing this and how to fix it?

Here's the code, just in case I implemented it wrong:

Code: Select all

init:
    python:
        def allvols(x):
            _preferences.set_volume("sfx", x)
            _preferences.set_volume("voice", x)
            _preferences.set_volume("music", x)
        allvolsad = ui.adjustment(range = 1.0, value = 1.0, changed=allvols) 
bar (in screen language)

Code: Select all

bar value 1.0 adjustment allvolsad range (80) xmaximum 80 ymaximum 10 thumb "soundbarthumb" thumb_shadow None thumb_offset 5 left_bar "soundbar_full" right_bar "soundbar_empty"

Post Reply

Who is online

Users browsing this forum: No registered users