Change narration text color with background

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
Moxanthia
Newbie
Posts: 3
Joined: Thu Feb 22, 2018 10:43 pm
Contact:

Change narration text color with background

#1 Post by Moxanthia »

Hiya, I'm trying to make a simple text-based game with Ren'Py. Some scenes take place on Earth and some in space. The scenes in space have a black background, while the ones on Earth have a white background. This being the case, I need to constantly switch between white and black narration text, respectively. It seems that I could use this: https://www.renpy.org/doc/html/gui_adva ... ui-rebuild I'm new to coding though, so I have no clue how this would work for my specific case.

User avatar
Draziya
Regular
Posts: 70
Joined: Sun Nov 26, 2017 8:50 am
Completed: this was for you. [NaNoRenO 19], Acetylene [AceJam19], Ah!! My Roommate is a Succubus Hellbent on World [MonJam 18], I Don't Have A Clue [QRMJam 18], Cautionary Tale [NaNoRenO 18], OP Dodge Cross [GGJ 18], Acetone [AceJam 18]
Projects: I'm a love interest in my childhood friend's reverse harem!!
Organization: Watercress
itch: Drazillion
Contact:

Re: Change narration text color with background

#2 Post by Draziya »

You could always define a second narrator for the black text:

Code: Select all

define black = Character (None, what_color="#000")
Image

User avatar
Moxanthia
Newbie
Posts: 3
Joined: Thu Feb 22, 2018 10:43 pm
Contact:

Re: Change narration text color with background

#3 Post by Moxanthia »

Yeah. I was just looking for a way to not have to write black before everything.

User avatar
Lezalith
Regular
Posts: 82
Joined: Mon Dec 21, 2015 6:45 pm
Contact:

Re: Change narration text color with background

#4 Post by Lezalith »

So, this is the default say() screen in screens.rpy file. Say screen is the screen that contains a textbox, a name, a dialogue... All that fancy stuff:

Code: Select all

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

    window:
        id "window"

        if who is not None:

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

        text what id "what"


    ## If there's a side image, display it above the text. Do not display on the
    ## phone variant - there's no room.
    if not renpy.variant("small"):
        add SideImage() xalign 0.0 yalign 1.0
Now, long story short, it basically takes the name of the character talking ("who") and the dialogue ("what") and displays it in some windows.
Focus on the text what id "what" , that is the line that displays the dialogue. First, let's branch it out onto multiple lines by adding a colon.

Code: Select all

text what:
    id "what"
Now we need something that will determine the color used. For this, we will use a simple variable.

Code: Select all

text what:
    id "what"
    if colorOfText == "white":
        color "#FFFFFF"
    else:
        color "#FF0000"
This simple code will add the "color" tag to our text, changing the color. But remember, variables always need to be defined before they are used. And because we need it defined before the screens are defined, we need to put it into init block.
Just outside of the screen, behind if not renpy.variant..., like this:

Code: Select all

    if not renpy.variant("small"):
        add SideImage() xalign 0.0 yalign 1.0

init -2 python:
    colorOfText = "white"


This will set the variable to "white" by default. Currently, it will show white text, and if we were to change that variable to anything else with $ colorOfText = "something", the text will turn red (#FF0000). Of course, you can customize this by changing the if/else branch.

User avatar
Moxanthia
Newbie
Posts: 3
Joined: Thu Feb 22, 2018 10:43 pm
Contact:

Re: Change narration text color with background

#5 Post by Moxanthia »

Thanks much!

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]