Setting color of a character after name change [SOLVED]

Knyghtblade

Newbie
Nov 3, 2017
63
14
Running into a bit of an issue following name input. I have it set up where you can input your own name for the MC, but when you do that, even if you select the default name it loses the who_color and what_color settings defined for that character.

Does anyone know of a way to retain or reapply them?

Cheers
 
Last edited:

mickydoo

Fudged it again.
Game Developer
Jan 5, 2018
2,446
3,548
This is mine

define t = Character("[name]" ,color="#FF0066")
 

Knyghtblade

Newbie
Nov 3, 2017
63
14
So I already have several characters defined like that - for example:

define mc = Character("Dave", who_color="#800080", what_color="#FF7F50")
define sm = Character("Wendy", who_color="#FFA500", what_color="#7FFFD4")

but when you allow a player to change the character name from those defined it breaks the color assignment. Looking for a way to put it back after that change.
 

moskyx

Forum Fanatic
Jun 17, 2019
4,008
12,979
So I already have several characters defined like that - for example:

define mc = Character("Dave", who_color="#800080", what_color="#FF7F50")
define sm = Character("Wendy", who_color="#FFA500", what_color="#7FFFD4")

but when you allow a player to change the character name from those defined it breaks the color assignment. Looking for a way to put it back after that change.
You have defined mc as "Dave" and sm as "Wendy". But when you give the player the option to change those names, how did you code it?

For instance, considering what you did in here
define mn = "[m] [n]"

This worked!! Many thanks to everyone for your input. I appreciate you all!!
You should add the color tag to define mn.

Also, I guess that this whole thing

Here is my code for this:

define m = Character("Dave", who_color="#800080", what_color="#FF7F50")
define n = Character("Narrating", who_color="#0000FF", what_color="#7FFFD4")

$ m = renpy.input("Input your name:", default = str(m))
$ m = m.strip()
if m == "":
$ m = "Dave"

n "The legendary %(m)s !"
is not exactly well coded, although I'm not an expert myself. But I don't think defining m twice is helping you now: the second time you define the variable (when players input their name) is actually overwriting your first definition of that variable, and this include the color tag
 

Meushi

Well-Known Member
Aug 4, 2017
1,146
12,728
So I already have several characters defined like that - for example:

define mc = Character("Dave", who_color="#800080", what_color="#FF7F50")
define sm = Character("Wendy", who_color="#FFA500", what_color="#7FFFD4")

but when you allow a player to change the character name from those defined it breaks the color assignment. Looking for a way to put it back after that change.
If you are changing the character name in the same way as your other question:
Python:
define m = Character("Dave", who_color="#800080", what_color="#FF7F50")
define n = Character("Narrating", who_color="#0000FF", what_color="#7FFFD4")

$ m = renpy.input("Input your name:", default = str(m))
$ m = m.strip()
if m == "":
    $ m = "Dave"
Then as moskyx said, the problem will be you're overwriting the mc Character() definition with the simple text string you got from renpy.input, so you've wiped out all the character styling.

That's why crabsinthekitchen and mickydoo have a 'name' variable in their character define - you update this 'name' variable with the player input name instead of the character define, so you're only changing the name, not all the character styling.
Python:
default mc_name = "Dave"
define mc = Character("[mc_name]", who_color="#800080", what_color="#FF7F50")

$ mc_name = renpy.input("Input your name:")
$ mc_name = mc_name.strip()
if mc_name == "":
    $ mc_name = "Dave"
Disclaimer: I'm not an expert either.
 
  • Like
Reactions: anne O'nymous

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,584
2,227
[...] I have it set up where you can input your own name for the MC, but when you do that, even if you select the default name it loses the who_color and what_color settings defined for that character.

Usually this happens when you incorrectly use the variable that refers to the Character() object when you use renpy.input() to get the player's name.

For example...

Python:
define mc = Character("John", who_color="#800080", what_color="#FF7F50"

#later...

    $ mc = renpy.input("What is your name? {i}(Press ENTER for 'Peter'){/i}")
    $ mc = mc.strip() or "Peter"

In this case, by using renpy.input(), the variable mc is initially a Character() object but is replaced by a Str() object by renpy.input(). String objects do not have colors, etc.

As an aside... I would recommend not using what_color at all. A single color for all character's speech is much easier to read. The only exception I can imagine might be where white is used for normal speech, but a light grey is used for character thoughts. Anyway... moving on...

The solution is to store the name of the character in a separate variable and have the Character() reference that new variable by name.

Python:
default mc_name = "Unnamed"

define mc = Character("[mc_name]", who_color="#800080", what_color="#FF7F50"

#later...

    $ mc_name = renpy.input("What is your name? {i}(Press ENTER for 'Peter'){/i}")
    $ mc_name = mc_name.strip() or "Peter"

In this new example, we now have mc_name as a string variable which holds the name of the character. Then the Character() object references this by standard string substitution of putting the variable name within square brackets within the string. That is... "[mc_name]".

For simplicity I've named the new variable mc_name because of it's connection to the main character's mc definition. But it could really be named anything. player_name comes to mind, but really... any variable name is fine.

If you have multiple characters with changeable names, you'd simply need an extra variable for each of those stored names.

Everywhere else in your game, you can use either [mc] or [mc_name] within strings to show the character's name. I would highly recommend using [mc] - as this allows for you to do the same thing for characters where their names aren't stored in separate variables.

Example...

Python:
default mc_name = "Unnamed"

define mc = Character("[mc_name]", who_color="#800080", what_prefix="\"", what_suffix="\"")
define mc_t = Character("[mc_name]", who_color="#800080", what_prefix="{i}(", what_suffix="){/i}")
define w = Character("Wendy", who_color="#F781F3", what_prefix="\"", what_suffix="\"")

label start:

    scene black with fade

    $ mc_name = renpy.input("What is your name? {i}(Press ENTER for 'Peter'){/i}")
    $ mc_name = mc_name.strip() or "Peter"

    mc "Hi, my name is [mc]."
    w "Oh, hi [mc], my name is [w]."

    mc_t "Oh my... [w] is gorgeous."

    "*** THE END ***"
    return

Yeah, yeah. I've gone a bit overboard. I'm using mc_t for the main character's thoughts. And using what_prefix and what_suffix to add the necessary characters to show any text as italic within parentheses.

My main point though was that even though Wendy doesn't have a changeable name, you can still use her Character() object to reference her name indirectly. Which means you could alter your game in the future to allow her name to be changed, with minimal fuss. It's not necessary, but it's a good habit in my opinion.
 
Last edited:

Knyghtblade

Newbie
Nov 3, 2017
63
14
moskyx, mickydoo, Meushi, 79flavors

All, Thanks so much for your help. As you can probably tell I am not a coder by profession (I am actually a producer and I have seen programmers in their native environment!) so everything you have explained to me here is greatly appreciated.

This is the first game I am making from scratch covering all the different disciplines and so to get started I decompiled other similar games and looked at how they were coded / solved problems. I guess I took ideas from different games that were not compatible with each other.

Again, many thanks! Your assistance is greatly appreciated.

Cheers!
 
  • Like
Reactions: Meushi