Controlling Preferences Values Via Buttons

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
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

#1 Post by curry nochi rice »

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.
Personal (R-13) | Now at IndieDB | Circle Cosine's itch.io
I wanna be done.

User avatar
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

#2 Post by PyTom »

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
Software > Drama • https://www.patreon.com/renpytom

User avatar
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

#3 Post by curry nochi rice »

PyTom wrote:I believe you can use Preference("music volume", 0.75).
Hmm... How about getting the value of thatthen displaying it?
Personal (R-13) | Now at IndieDB | Circle Cosine's itch.io
I wanna be done.

philat
Eileen-Class Veteran
Posts: 1909
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Controlling Preferences Values Via Buttons

#4 Post by philat »

_preferences.get_volume("music") returns the volume setting as a float between 0 and 1.

User avatar
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

#5 Post by curry nochi rice »

philat wrote:_preferences.get_volume("music") returns the volume setting as a float between 0 and 1.
Thanks. Gonna test this baby later unless you guys could compile and return bugs it in your mind. :lol:

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)
Personal (R-13) | Now at IndieDB | Circle Cosine's itch.io
I wanna be done.

User avatar
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

#6 Post by curry nochi rice »

Btw, thanks admin(s) for moving this thread to the right section.

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"
Personal (R-13) | Now at IndieDB | Circle Cosine's itch.io
I wanna be done.

philat
Eileen-Class Veteran
Posts: 1909
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Controlling Preferences Values Via Buttons

#7 Post by philat »

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

User avatar
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

#8 Post by curry nochi rice »

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
Confirmed. It doesn't behave as planned. Thanks for this fix.

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.
Personal (R-13) | Now at IndieDB | Circle Cosine's itch.io
I wanna be done.

Post Reply

Who is online

Users browsing this forum: Google [Bot], Rhapsy