Playing sound when changing sound volume bar?

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
Saa
Regular
Posts: 32
Joined: Tue Aug 20, 2013 7:11 pm
Tumblr: nipahgirl
Contact:

Playing sound when changing sound volume bar?

#1 Post by Saa » Sat Apr 27, 2019 2:27 pm

Hi! I'm trying to make it so, when you change the sound volume in the preferences menu, a sound plays (so you can immediately hear how your new volume will sound). I know there's a "test" button, but I don't want it; I want the sound to play on its own without the user needing to do anything. I've tried this code:

Code: Select all

if config.has_sound:

	label _("Sound Volume")

	hbox:
		bar value Preference("sound volume") changed renpy.sound.play('bgm/click.wav')
But for some reason, it just makes sound play every single time I click something interactive (which could be desirable, if it didn't also play as soon as the game opens). How do I make it work?

User avatar
nature1996
Regular
Posts: 62
Joined: Wed Jun 21, 2017 10:35 am
Contact:

Re: Playing sound when changing sound volume bar?

#2 Post by nature1996 » Mon May 06, 2019 11:25 am

Maybe you should only play the sound when the bar is "hovered", then stop it when "unhovered", as "changed" also give the change value as an argument:
https://www.renpy.org/doc/html/screens.html?#bar

The problem might be due to the fact that ren'py predict the screens effects and content even before they are shown (for speed reason I think), but that mean that it might compute "renpy.sound.play('bgm/click.wav')" as soon as you can open the screen, and not when you interact with the bar. If you want the sound to play for the whole screen, you could use the "on "show"" key-word to start it and "on "hide"" to stop it:
https://www.renpy.org/doc/html/screens.html?#on

Hope that could help
Je parle aussi français

Post Reply

Who is online

Users browsing this forum: No registered users