how to change color to a name written by the player?

zenergyblack

Newbie
Mar 29, 2022
26
3
It's a little nonsense but I don't want to waste too much time with this either, if you can help me.

I want both the default name and the name chosen by the player to change color to the one I choose

Anotación 2022-09-02 025354.png
Anotación 2022-09-02 025414.png
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,585
2,229
The name displayed by RenPy, when that character is speaking is already being changed by the , color="#0EFBE9" portion of the Character definition.

Or do you mean when the player's name appears in dialogue?

Something like:
Hello, my name is William Lothbrok and I will be [...]

I don't have access to RenPy right now, but I'm thinking something like:

Python:
    if not Playername:
        $ Playername = "William Lothbrok"

    $ Playername = "{color=#" + PN.who_color + "}" + Playername + "{/color}"

    PN "I have to present myself properly to make a good impression, alth..."

Edit: Removed incorrect line Playername "I have to present myself properly to make a good impression, alth..." (which is exactly the problem the OP has... and I just copied like an idiot).

Using the text tag to colorize the text where ever it is used. You'd need to check the value of PN.who_color to figure out whether the hash (#) symbol is needed or not.


As a complete aside, it's unusual for the player to choose a FULL name when entering a name. More common is to enter a Forename and Surname separately. It means characters can speak to you as "William" rather than "William Lothbrok" all the time. Though maybe full names are appropriate for your game.

Something more like:

Python:
default pname = "Unknown"
default psurname = "Unknown"

define narrator = Character("", what_color="#FFFF66")

define mc = Character("[pname]", color="#0EFBE9", what_prefix='"', what_suffix='"')
define mc_t = Character("[pname]", color="#0EFBE9", what_prefix='{i}(', what_suffix='){/i}', what_color="#BBBBBB")

label start:

    scene black with fade

    $ pname = renpy.input("What is your name? (Default is 'William')", exclude="[]{}")
    $ pname = pname.strip() or "William"

    $ psurname = renpy.input("What is your family name? (Default is 'Lothbrok')", exclude="[]{}")
    $ psurname = psurname.strip() or "Lothbrok"

    mc "[mc] is speaking."
    mc_t "[mc] is thinking."

    mc "I am Mr [psurname]. [pname] [psurname]."

    return

I should point out that I prefer to use the Character object when using people's names in dialogue, rather than the variables it points at - except when referring to surnames. It's a tiny thing, but means the same technique works for other characters too. Doing it this way ensures it's possible to improve the game later by allowing the player to rename other characters too.
The what_prefix, etc is explained in a little more detail in this post.
 
Last edited:

zenergyblack

Newbie
Mar 29, 2022
26
3
I have controlled the color text, but as I tell you, the character's name does not change color.


I am attaching pictures for you to see.

Captura de pantalla 2022-09-02 153239.png

Captura de pantalla 2022-09-02 153256.png

Captura de pantalla 2022-09-02 153330.png

It leaves it by default that gives the renpy

Captura de pantalla 2022-09-02 153507.png


Nor does the color change if the default name is not left
 

guest1492

Member
Apr 28, 2018
322
272
Have you changed Playername "Hello, my name is [Playername] and I will be participating with all..." to PN "Hello, my name is [PN] and I will be participating with all..." yet?

EDIT: If you meant you wanted the name to also be colored inside the dialogue (as in someone mentions the player's name and not just when the speech box displays the speaker's name) then check the first part of the post by 79flavors . I had to make a slight adjustment to make it work when I tried it:
Code:
$ Playername = "{color=#" + PN.who_args['color'] + "}" + Playername + "{/color}"
PN "Hello, my name is [Playername] and I will be participating with all..."
 
Last edited:

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,041
3,141
create a new test project and test the code that 79flavors suggested to see if it work there

you might of change something in the gui or somewhere that might be overwriting it


just test it and the works just fine

screenshot0001.png screenshot0002.png screenshot0003.png
 

moskyx

Forum Fanatic
Jun 17, 2019
4,010
12,989
It's as simple as using the variable PN as the sayer instead of Playername. Because that's the one you're defining with the color tags.

PN "Hello, I'm [Playername]."
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,585
2,229
I have controlled the color text, but as I tell you, the character's name does not change color.
EDIT: D'OH. I'm an idiot.
In your original example, you're using Playername to talk.
Playername is a string variable that doesn't have other attributes (like color). RenPy will use it, but will print it using the default colors.
(and worse... I copied your exact error when writing out my reply and still didn't notice).

What you want instead is:

Python:
PN "I have to present myself properly to make a good impression, alth..."
Using PN (the Character()) and not Playername (the simple string variable).

Others above me have already pointed this out. Including guest1492 and moskyx .

Personally, unless you have a lot of dialogue already, I would call the character mc or at least pn instead of PN. Typing uppercase characters like that all the way through your script will be a PITA eventually.

So here's my other (wrong) reply... included because... well, it took a while to type...

Ah. Okay.
So you're talking about the standard name, printed above the dialogue spoken by the player's character.

Most of my original reply isn't what you were looking for.

However, you still clearly have an issue.

My first suggestion would be to create a brand new "test" project. Name it anything you like, since you'll probably be deleting it shortly anyway.

Then create the most simple RenPy game ever...

Python:
define e = Character("Eileen", color="#FF0000")

label start:

    scene black with fade

    e "You've created a new Ren'Py game."
    e "Once you add a story, pictures, and music, you can release it to the world!"

    return

(which is basically the starter template with all the comments removed and a color= parameter added)
Run the game... Eileen's name should be in RED.

Change the line to:
define e = Character("Eileen", color="#00CCFF")
Run the game... Eileen's name should now be CYAN.

Which doesn't help much, except to prove to you that under normal circumstances, color= works just fine.
If it doesn't... erm... Either RenPy is broken or you have the world's most unique monitor failure. :devilish:

So delete the test project, and let's start thinking about your main game.

The main processing of the screen dialogue is handled by a predefined screen called screen say(who, what): within the screens.rpy file. I'm guessing you've either messed with that, or the supporting configuration variables within gui.rpy.

So within the say() screen, there's a bit of code that prints the character's name (if there is one for this bit of dialogue). It's known as namebox.

The namebox definition is linked to a style called namebox_label, which in turn is linked to another style say_label.

By default, say_label looks like this:

Python:
style say_label:
    properties gui.text_properties("name", accent=True)
    xalign gui.name_xalign
    yalign 0.5

If it doesn't look like that, it's because you messed with it at some point... and...
You don't have permission to view the spoiler content. Log in or register now.

If you didn't mess with that bit. Did you perhaps make any alternations to the gui.rpy file?

The properties gui.text_properties("name" ... bit of the code essentially says to fill in the gaps of the style definition using variables called gui.name_{something} where {something} is whatever parameters it needs for the style.

If (for example), you've added a new line like:
define gui.name_text_color = "#00FF00", it could override things and make the name GREEN.
(though in fairness, the color specified on the Character() definition overrides even that).

It's difficult to say for sure. But my guess is that you've tweaked the screen say() at some point.
 
Last edited: