Changing characters' names and text color

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
SelLi
Miko-Class Veteran
Posts: 550
Joined: Fri Apr 27, 2012 4:49 pm
Completed: The Silent Column
Projects: Ethereal Overflow
Deviantart: SelLillianna
itch: SelLillianna
Location: Canada
Contact:

Changing characters' names and text color

#1 Post by SelLi »

Hello everyone.
I'm having some trouble with changing characters' names and text color.
Long ago in a distant land, I, SelLi-
asked about how to change a character's name, and I was helped out by being given this useful code.

Code: Select all

init python:
    def dCharacter(name_expr, **properties):
        return Character(name_expr, dynamic=True, ctc_position="fixed", what_prefix='"', what_suffix='"', **properties)
With-which I can do something like this:

Code: Select all

$DylanName=Stranger
Dylan=dCharacter(DylanName, color="#89", what_color="#89")
#later~
Sammy"Who ARE you?"
$DylanName=Dylan
Dylan"My name is Dylan."
I'm wondering now, though, if I can change a character's name and who/what text color.
The reason I want to learn this is for situations where someone is under cover or something similar.
When Bob is undercover as Joe and he talks to Sammy, they have quite a lengthy dialogue, with his name being displayed as Joe and his who/what text color being displayed as Joe's colors.
But according to Sammy's choices earlier on, Bob may have the exact same lengthy dialogue with Sammy without Bob being undercover. So his name would be displayed as Bob, and his who/what text would be in Bob's colors.

I'd like to have Bob's name and colors change without making a separate character, since I don't want to have the same lengthy dialogue twice, just with "Joe" replacing "Bob" at the beginning of Bob's lines.

I tried:

Code: Select all

init python:
    def dCharacter(name_expr, **properties):
        return Character(name_expr, dynamic=True, ctc_position="fixed", what_prefix='"', what_suffix='"', **properties)

    joe=dCharacter("Joe", color="#25", what_color="#25")
    bob=dCharacter("Bob", color="#50", what_color="#50")
    b=joe
So that I would be able to change "b" between "bob" and "joe" as I pleased, but that isn't working...
What am I doing wrongly? Can I please get some help?

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: Changing characters' names and text color

#2 Post by xavimat »

Your code throws an exception not related with this topic:

Code: Select all

Exception: Color string must be 3, 4, 6, or 8 hex digits long.
Correcting this, your code works for me. I mean, using another character "b" in that long dialogue and defining before that dialogue if b=bob or b=joe.
Also, you really don't need to define bCharacter if the only change you need is the name of the character as a variable. There are two ways of doing this (using dynamic=True inside the Character definition or using "[variable]" as the name of the normal character.
My code (more or less copied from yours), works Ok:

Code: Select all

define joe = Character("[joe_name]", color="#259", what_color="#259")
define bob = Character("[bob_name]", color="#950", what_color="#950")
label start:
    $ joe_name = "Joe"
    $ bob_name = "Bob"
    menu:
        "Bob":
            $ b = bob
        "Joe":
            $ b = joe
    b "You've created a new Ren'Py game."
    b "Once you add a story, pictures, and music, you can release it to the world!"
    return
Also, now Ren'Py allows you to use the same name for a variable and for a character. (joe could be the character and also some sort of stat). In your case you need to avoid this, because the line b=joe would be interpreted as "b=the variable joe" and not "b=the character joe". As long as you don't use 'joe' or 'bob' as variable names, this code should be sound.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

Post Reply

Who is online

Users browsing this forum: No registered users