[solved] SetField action not changing persistent color variable

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
warmsundae
Regular
Posts: 61
Joined: Tue Feb 24, 2015 9:51 pm
Skype: electriclan
Soundcloud: lanterny
Location: korea
Contact:

[solved] SetField action not changing persistent color variable

#1 Post by warmsundae »

I have a pretty simple black-on-white interface, but I realized it could get a little hard on the eyes. so I'm trying to make two themes, one a default "light mode" and one "dark mode" that changes the color of the text and background.

first, I changed some stuff so the gui could be controlled by just a few variables:
gui.rpy

Code: Select all

default persistent.text_color = "#000"
default persistent.menu_color = "#6cce6f"
default persistent.background = "#fff"

## The colors used for dialogue and menu choice text.
define gui.interface_text_color = persistent.menu_color
define gui.text_color = persistent.text_color

## The images used for the main and game menus.
define gui.main_menu_background = persistent.background
define gui.game_menu_background = persistent.background
screens.rpy

Code: Select all

style nvl_window:
    background persistent.background

style main_menu_frame:
    background persistent.background
then I added a new set of buttons in the Preferences screen:

Code: Select all

screen preferences():

    tag menu

    use game_menu(_("Preferences"), scroll="viewport"):

        vbox:

            hbox:
                box_wrap True

                ...
                
                vbox:
                    style_prefix "radio"
                    label _("Theme")
                    textbutton _("Light") action [ SetField(persistent, 'background', "#fff"), SetField(persistent, 'text_color', "#000") ]
                    textbutton _("Dark") action [ SetField(persistent, 'background', "#000"), SetField(persistent, 'text_color', "#fff") ]
but it doesn't work. is it because it's a persistent color variable? or am I missing something?

(I also found something about Style Preferences, but I think it might be outdated - either that or I didn't implement it properly.)
Last edited by warmsundae on Sat Dec 23, 2017 10:58 pm, edited 1 time in total.

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: SetField action not changing persistent color variable

#2 Post by Remix »

A more readable (and perhaps easier to follow/understand/implement) version of that exists in the Documentation

Though I am not entirely sure if your code should work, personally I have tended toward using _preference rather than _persistent when dealing with styling and visual settings.
To test:
Change the
default persistent.nnnnn
to
default preference.nnnnn
Change the
SetField( persistent, 'nnnn',
to
SetField( _preferences, 'nnnn', # note the underscore here and the 's' pluralization

Sub-note: Maybe first try just changing SetField( persistent, 'nnnn', to SetField( _persistent, 'nnnn', (dunno about plural... )
Frameworks & Scriptlets:

User avatar
warmsundae
Regular
Posts: 61
Joined: Tue Feb 24, 2015 9:51 pm
Skype: electriclan
Soundcloud: lanterny
Location: korea
Contact:

Re: SetField action not changing persistent color variable

#3 Post by warmsundae »

aw man. I tried changing stuff to preference.-- like you said, but it didn't work.

but I think I'm figuring things out! it turns out I actually didn't implement style preferences properly. I was stuck there because I didn't know what style objects were, but I figured it out! all I had to do was use the style inspector or look in screens.rpy.


it works now :D
here it is, in case anyone finds a use for it:
script.rpy

Code: Select all

init python:
    # light and dark theme text
    renpy.register_style_preference("nvl_thought", "light", style.nvl_thought, "color", "#000")
    renpy.register_style_preference("nvl_thought", "dark", style.nvl_thought, "color", "#fff")

    # nvl window background
    renpy.register_style_preference("nvl_window", "light", style.nvl_window, "background", "#fff")
    renpy.register_style_preference("nvl_window", "dark", style.nvl_window, "background", "#000")

    # menu background
    renpy.register_style_preference("main_menu_frame", "light", style.main_menu_frame, "background", "#fff")
    renpy.register_style_preference("main_menu_frame", "dark", style.main_menu_frame, "background", "#000")

    renpy.register_style_preference("game_menu_outer_frame", "light", style.game_menu_outer_frame, "background", "#fff")
    renpy.register_style_preference("game_menu_outer_frame", "dark", style.game_menu_outer_frame, "background", "#000")

    # navigation textbuttons
    renpy.register_style_preference("gui_button_text", "light", style.gui_button_text, "color", "#000")
    renpy.register_style_preference("gui_button_text", "dark", style.gui_button_text, "color", "#fff")
    renpy.register_style_preference("gui_button_text", "light", style.gui_button_text, "hover_color", "#6cc")
    renpy.register_style_preference("gui_button_text", "dark", style.gui_button_text, "hover_color", "#6cc")
screens.rpy

Code: Select all

screen preferences():

   ...

                vbox:
                    style_prefix "radio"
                    label _("Theme")
                    textbutton _("Light") action [ StylePreference("nvl_thought", "light"), StylePreference("nvl_window", "light"), StylePreference("main_menu_frame", "light"), StylePreference("game_menu_outer_frame", "light"), StylePreference("gui_button_text", "light") ]
                    textbutton _("Dark") action [ StylePreference("nvl_thought", "dark"), StylePreference("nvl_window", "dark"), StylePreference("main_menu_frame", "dark"), StylePreference("game_menu_outer_frame", "dark"), StylePreference("gui_button_text", "dark") ]
thanks for directing me to the docs, it helped a bunch!

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: SetField action not changing persistent color variable

#4 Post by Remix »

All good :)
Well done on getting it working and posting the code as example for others.
Frameworks & Scriptlets:

Post Reply

Who is online

Users browsing this forum: No registered users