"Reset to default" preferences?

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
Gumaster
Regular
Posts: 93
Joined: Sun Sep 06, 2009 6:54 am
Contact:

"Reset to default" preferences?

#1 Post by Gumaster »

There was a thread almost a year ago about this, but I'm curious as to how this is done with screen language.
I can set *most* values by listing the relevant actions (such as Preferences("skip", "seen")), but I'm stuck with music and sound volumes, as there doesn't seem to be a way to set them to maximum (or a certain value) outside of using bars

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: "Reset to default" preferences?

#2 Post by PyTom »

Here's an action that can handle this for you. Untested, of course:

Code: Select all

init python:
    class SetVolume(Action):
        def __init__(self, mixer, value):
            self.mixer = mixer
            self.value = value

        def __call__(self):
            _preferences.set_volume(self.mixer, self.value)

        def get_selected(self):
            return _preferences.get_volume(self.mixer) == self.value
When calling this, mixer should be one of "music", "sfx", or "voice". The volume should be between 0.0 and 1.0. For example:

Code: Select all

screen music_volume:
     frame:
         has vbox

         label "Music Volume"
         textbutton "0" action SetVolume("music", 0.0)
         textbutton "1" action SetVolume("music", 0.25)
         textbutton "2" action SetVolume("music", 0.5)
         textbutton "3" action SetVolume("music", 0.75)
         textbutton "4" action SetVolume("music", 1.0)
I'm not sure how great an idea this would be - I think I'd want more control over volume. That's why this isn't a default action. (Feedback is welcome.)
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

Gumaster
Regular
Posts: 93
Joined: Sun Sep 06, 2009 6:54 am
Contact:

Re: "Reset to default" preferences?

#3 Post by Gumaster »

Works (at least, to the extent that I tested it)
I'm not using it as a replacement for the volume bar (I'd prefer more control too), simply as a way to set music and sound volumes to max using the 'reset to default' button

User avatar
SleepKirby
Veteran
Posts: 255
Joined: Mon Aug 09, 2010 10:02 pm
Projects: Eastern Starlight Romance, Touhou Mecha
Organization: Dai-Sukima Dan
Location: California, USA
Contact:

Re: "Reset to default" preferences?

#4 Post by SleepKirby »

I have a Reset to Defaults button that sets all the preferences to default. Not sure if it's what you want, but just throwing in an idea. It looks something like this:

Code: Select all

        # This is in my preferences screen code.
        # When you click this hotspot, the function ResetToDefaults is called.  You could achieve the same thing with a button
        hotspot (569, 477, 188, 106) clicked ResetToDefaults

Code: Select all

init python:
    def ResetToDefaults():
        _preferences.transitions = 2    # All transitions on
        _preferences.text_cps = config.default_text_cps
        _preferences.afm_time = config.default_afm_time
        _preferences.afm_enable = config.default_afm_enable
        _preferences.skip_unseen = False
        _preferences.skip_after_choices = False
        _preferences.set_volume('sfx', 1.0)
        _preferences.set_volume('music', 1.0)
        persistent.annotations_enable = False    # This is an option specific to my game
        
        renpy.restart_interaction()    # Update the screen to reflect the preference changes

Post Reply

Who is online

Users browsing this forum: No registered users