By default, Ren'Py comes with a volume test button in the preferences screen. You can set a sound to play by making sure sounds are enabled and defining the music file to play within Options.rpy
Code: Select all
define config.has_sound = True
define config.sample_sound = "music/effects/gun1.wav"
Code: Select all
if config.has_sound:
label _("Sound Volume")
hbox:
bar value Preference("sound volume")
if config.sample_sound:
textbutton _("Test") action Play("sound", config.sample_sound)
For that, we can use Ren'Py random.
Directly underneath the start of the screen, add the following:
Code: Select all
screen preferences():
$ sfx_test = renpy.random.randint(1, 3)# range of samples to use. For more or less samples, change the 3 to suit.
So now you need to define what those choices are.
Go back to Options.rpy and replace this line define config.sample_sound = "music/effects/gun1.wav" with:
Code: Select all
define config.sample_sound = ["music/effects/gun1.wav", "music/effects/gun2.wav", "music/effects/glass1.wav"]
Go to the Screens.rpy file again and change:
Code: Select all
if config.sample_sound:
textbutton _("Test") action Play("sound", config.sample_sound)
Code: Select all
if config.sample_sound:
if sfx_test == 1:
textbutton _("Test") action [ Play("sound", "music/effects/gun1.wav") ]
if sfx_test == 2:
textbutton _("Test") action [ Play("sound", "music/effects/gun2.wav") ]
if sfx_test == 3:
textbutton _("Test") action [ Play("sound", "music/effects/glass1.wav") ]