[...] 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.