Controlling Preferences Values Via Buttons
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.
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.
- curry nochi rice
- Miko-Class Veteran
- Posts: 746
- Joined: Sat Mar 27, 2010 3:12 am
- Projects: Delicatessen, Whom to Notice, Start of Something, Love Sorcery
- Organization: Circle Cosine
- IRC Nick: Curry
- Skype: after.curry.rice
- itch: project-rothera
- Contact:
Controlling Preferences Values Via Buttons
Hallo all!
Is it possible to control music/voice/sfx volume, and text speed via buttons instead of bars? If so, what variables to I need to control? Code greatly appreciated. I'm making something that does't have the luxury of space to use bars.
Holy fudge I just posted this on the wrong subforum.
Is it possible to control music/voice/sfx volume, and text speed via buttons instead of bars? If so, what variables to I need to control? Code greatly appreciated. I'm making something that does't have the luxury of space to use bars.
Holy fudge I just posted this on the wrong subforum.
- PyTom
- Ren'Py Creator
- Posts: 16093
- Joined: Mon Feb 02, 2004 10:58 am
- Completed: Moonlight Walks
- Projects: Ren'Py
- IRC Nick: renpytom
- Github: renpytom
- itch: renpytom
- Location: Kings Park, NY
- Contact:
Re: Controlling Preferences Values Via Buttons
I believe you can use Preference("music volume", 0.75).
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom(When was the last time you backed up your game?)
Software > Drama • https://www.patreon.com/renpytom
- curry nochi rice
- Miko-Class Veteran
- Posts: 746
- Joined: Sat Mar 27, 2010 3:12 am
- Projects: Delicatessen, Whom to Notice, Start of Something, Love Sorcery
- Organization: Circle Cosine
- IRC Nick: Curry
- Skype: after.curry.rice
- itch: project-rothera
- Contact:
Re: Controlling Preferences Values Via Buttons
Hmm... How about getting the value of thatPyTom wrote:I believe you can use Preference("music volume", 0.75).
Re: Controlling Preferences Values Via Buttons
_preferences.get_volume("music") returns the volume setting as a float between 0 and 1.
- curry nochi rice
- Miko-Class Veteran
- Posts: 746
- Joined: Sat Mar 27, 2010 3:12 am
- Projects: Delicatessen, Whom to Notice, Start of Something, Love Sorcery
- Organization: Circle Cosine
- IRC Nick: Curry
- Skype: after.curry.rice
- itch: project-rothera
- Contact:
Re: Controlling Preferences Values Via Buttons
Thanks. Gonna test this baby later unless you guys could compile and return bugs it in your mind.philat wrote:_preferences.get_volume("music") returns the volume setting as a float between 0 and 1.
Code: Select all
def addMusicVolume(vol):
oldSoundVol = _preferences.get_volume("music")
newSoundVol = float(vol + oldMusicVol)
Preference("music volume", newMusicVol)
def decMusicVolume(vol):
oldSoundVol = _preferences.get_volume("music")
newSoundVol = float(oldMusicVol - vol)
Preference("music volume", newMusicVol)
- curry nochi rice
- Miko-Class Veteran
- Posts: 746
- Joined: Sat Mar 27, 2010 3:12 am
- Projects: Delicatessen, Whom to Notice, Start of Something, Love Sorcery
- Organization: Circle Cosine
- IRC Nick: Curry
- Skype: after.curry.rice
- itch: project-rothera
- Contact:
Re: Controlling Preferences Values Via Buttons
Btw, thanks admin(s) for moving this thread to the right section.
Actual implementation as follows:
Actual implementation as follows:
Code: Select all
hbox spacing 70:
vbox spacing 5:
label _("Music Volume")
#text "{size=30}Music Volume{/size}" color "#000000"
#bar value Preference("music volume") style "slein_bar" xsize 280 #style "pref_slider"
frame:
xsize 280
xminimum 280 xmaximum 280
#has hbox
$ oldVol = _preferences.get_volume("music")
$ stringVol = int(oldVol * 100)
if stringVol > 100:
$ oldVol = 1.0
$ stringVol = 100
if stringVol <= 0:
$ oldVol = 0.0
$ stringVol =0
$ stringVol = str(stringVol)
imagebutton:
xanchor 0.5 xalign 0.2 yalign 0.5
action Preference("music volume", oldVol -0.05) #decMusicVolume(0.25)
idle "assets/ui/icons_circle/minus63_w.png"
hover "assets/ui/icons_circle/minus63_ls.png"
text stringVol xanchor 0.5 xalign 0.5 yalign 0.5
imagebutton:
xanchor 0.5 xalign 0.8 yalign 0.5
action Preference("music volume", oldVol +0.05) #addMusicVolume(0.25)
idle "assets/ui/icons_circle/add128_w.png"
hover "assets/ui/icons_circle/add128_ls.png"
Re: Controlling Preferences Values Via Buttons
You can do the part constraining the volume to between 0 and 100 much more simply. These two lines can replace everything between the commented out has hbox and the buttons.
Code: Select all
$ oldVol = min(1.0, max(0.0, _preferences.get_volume("music")))
$ stringVol = str(int(math.ceil(oldVol * 100))) # have to import math to use ceiling -- otherwise, the floating rounding up can get weird and not move in exact increments of 5
- curry nochi rice
- Miko-Class Veteran
- Posts: 746
- Joined: Sat Mar 27, 2010 3:12 am
- Projects: Delicatessen, Whom to Notice, Start of Something, Love Sorcery
- Organization: Circle Cosine
- IRC Nick: Curry
- Skype: after.curry.rice
- itch: project-rothera
- Contact:
Re: Controlling Preferences Values Via Buttons
Confirmed. It doesn't behave as planned. Thanks for this fix.philat wrote:You can do the part constraining the volume to between 0 and 100 much more simply. These two lines can replace everything between the commented out has hbox and the buttons.
Code: Select all
$ oldVol = min(1.0, max(0.0, _preferences.get_volume("music"))) $ stringVol = str(int(math.ceil(oldVol * 100))) # have to import math to use ceiling -- otherwise, the floating rounding up can get weird and not move in exact increments of 5
BTW, how do I get the values of auto text and text speed? I can get a basic gist of it basing from how you got the values for the volumes but I just want to make sure before trying.
Who is online
Users browsing this forum: Google [Bot], Rhapsy