[Solved] Using If/Else Statements To Change Text Color For Night Mode

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
pepperdu
Newbie
Posts: 12
Joined: Mon Nov 05, 2018 9:03 pm
Contact:

[Solved] Using If/Else Statements To Change Text Color For Night Mode

#1 Post by pepperdu »

Thanks for reviewing.

I am in the process of trying to implement a "night mode" linked to buttons on my menu's imagemap. I've figured out how to connect the screen being displayed to the state of a specific variable, but I haven't been able to figure out how to use this to change the color dialogue text.

Here is what I have so far:

Variable defined:

Code: Select all

default persistent.night_mode = "False"
Variable state linked to button:

Code: Select all

screen preferences():

    imagemap:
        ground 'gui/MenuButtons.png'
        hover 'gui/MenuHover.png'
        selected_idle 'gui/MenuSelect.png'
        selected_hover 'gui/MenuSelect.png'

        hotspot (475, 340, 127, 93) action Quit(confirm=False)
        hotspot (502, 98, 111, 47) action Preference("music mute", "enable")
        hotspot (406, 98, 72, 47) action Preference("music mute", "disable")
        hotspot (258, 472, 132, 92) action Return()
        hotspot (445, 253, 154, 42) action SetVariable("persistent.night_mode", True)
        hotspot (43, 250, 100, 49) action SetVariable("persistent.night_mode", False)
Action Linked to variable state:

Code: Select all

screen callmenu ():
    imagemap:

        ground "gui/showmenu.png"
        hover "gui/showmenuhover.png"
        idle "gui/showmenu.png"
        selected_idle "gui/showmenuselect.png"
        selected_hover "gui/showmenuselect.png"

        hotspot (0, 1, 637, 104)action ShowMenu("preferences")hovered

    if persistent.night_mode:
        add "images/bg alts.png"
    else:
        add "images/bg main.png"
This allows me to change all of my screens, but I can't figure out how to change my text color.
I've tried variations of a couple of solutions posted on the forum, but none of them seem to work.

Utilizing style preferences, as suggested in these posts, hasn't worked because "StylePreference' is not a keyword argument or valid child for the hotspot statement"
viewtopic.php?t=47179
viewtopic.php?t=47012

I've tried applying if/else statements to the say screen as suggested in these posts, but I keep being told that

Code: Select all

color
and

Code: Select all

text_color
are "not a keyword argument or valid child" for window statements when I try to add them to the say screen.

Code: Select all

screen say(who, what):
    style_prefix "say"

    window:
        id "window"

        if who is not None:

            window:
                id "namebox"
                style "namebox"
                text who id "who"

        text what id "what"
        if persistent.night_mode:
            color "000000"
        else:
            color "ffffff"
viewtopic.php?t=48247
https://lemmasoft.renai.us/forums/view ... ns#p492879

Is there something else I should try?

Any help would be appreciated.
Last edited by pepperdu on Wed Jan 15, 2020 10:22 pm, edited 2 times in total.

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

Re: Hotspots, Variables, And Text Color

#2 Post by philat »

Minor errors in either case: the lack of space between the coordinates and action, and the indentation of color needs to under the text rather than under the window.

pepperdu
Newbie
Posts: 12
Joined: Mon Nov 05, 2018 9:03 pm
Contact:

Re: Hotspots, Variables, And Text Color

#3 Post by pepperdu »

Thanks so much for taking a look!

I tried indenting and so that my code looks like this:

Code: Select all

screen say(who, what):
    style_prefix "say"

    window:
        id "window"

        if who is not None:

            window:
                id "namebox"
                style "namebox"
                text who id "who"

        text what id "what"
            if persistent.night_mode:
                color "000000"
            else:
                color "ffffff"
But got the following error:

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/screens.rpy", line 113: Line is indented, but the preceding text statement does not expect a block. Please check this line's indentation.
    if persistent.night_mode:
    ^

Ren'Py Version: Ren'Py 7.3.5.606
Wed Jan 15 13:10:14 2020

rayminator
Miko-Class Veteran
Posts: 793
Joined: Fri Feb 09, 2018 12:05 am
Location: Canada
Contact:

Re: Hotspots, Variables, And Text Color

#4 Post by rayminator »

it's telling you that the text statement doe not expect a block so it's telling to take the if statement out of the block

Code: Select all

screen say(who, what):
    style_prefix "say"

    window:
        id "window"

        if who is not None:

            window:
                id "namebox"
                style "namebox"
                text who id "who"

        text what id "what"
        
        if persistent.night_mode:
            color "000000"
        else:
            color "ffffff"

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

Re: Hotspots, Variables, And Text Color

#5 Post by philat »

Indentation requires a colon (:).

rayminator
Miko-Class Veteran
Posts: 793
Joined: Fri Feb 09, 2018 12:05 am
Location: Canada
Contact:

Re: Hotspots, Variables, And Text Color

#6 Post by rayminator »

it should look like this

Code: Select all

screen say(who, what):
    style_prefix "say"

    window:
        id "window"

        if who is not None:

            window:
                id "namebox"
                style "namebox"
                text who id "who"

        text what id "what":        
            if persistent.night_mode:
                color "000000"
            else:
                color "ffffff"

pepperdu
Newbie
Posts: 12
Joined: Mon Nov 05, 2018 9:03 pm
Contact:

Re: Hotspots, Variables, And Text Color

#7 Post by pepperdu »

Thank you all for your help. if/else statement needed to be indented, and the colon was missing. Adding that fixed my issue.

Post Reply

Who is online

Users browsing this forum: Google [Bot]