How can I customize a changeable name? [Solved]

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
Flowers from Nowhere
Regular
Posts: 138
Joined: Sun Feb 10, 2013 8:16 am
Completed: The Crystal Castle
Projects: My Ninja Life
Contact:

How can I customize a changeable name? [Solved]

#1 Post by Flowers from Nowhere » Sun Nov 03, 2013 9:29 am

If I just assign a character a name I can change the color that the name appears in, add prefixes and suffixes, etc. just by defining the character that way:

Code: Select all

define unknown = Character('???', color="#c8ffc8", what_prefix="\"", what_suffix="\"")
With this code in place anything that unknown says will be in quotations and the name "???" will appear in the name box in the given color.

But what if I want to let the player rename the character? The way I know to do that is set a variable:

Code: Select all

$ person = renpy.input("My name is...", "Some Bloke")
Which will allow me to use person as a character but I don't know how to customize the color of the name (in this case the default name "Some Bloke") or add prefixes and suffixes.

Is there a way to do this?
Last edited by Flowers from Nowhere on Sun Nov 03, 2013 2:33 pm, edited 1 time in total.

User avatar
Megaman Z
Miko-Class Veteran
Posts: 829
Joined: Sun Feb 20, 2005 8:45 pm
Projects: NaNoRenO 2016, Ren'Py tutorial series
Location: USA
Contact:

Re: How can I customize a changeable name?

#2 Post by Megaman Z » Sun Nov 03, 2013 10:28 am

Set the "name" of the character to the name of the variable (as a string) and specify dynamic=True on the same character. Alternatively, use DynamicCharacter for this, setting the "name" as the name of the variable. DynamicCharacter(name, [...]) is equivalent to Character(name, dynamic=True, [...])

In context, you're probably looking for something along the following lines:

Code: Select all

# Variable we're storing the name in
init:
    $ person = "???"

# Character who will be referred to as whatever person (see above) is at the time
define unknown = DynamicCharacter("person", color="#c8ffc8", what_prefix="\"", what_suffix="\"")
With that, at some point in the actual script (after label start or wherever), set person to be the result of renpy.input() as before and the name will change.
~Kitsune Zeta

User avatar
Flowers from Nowhere
Regular
Posts: 138
Joined: Sun Feb 10, 2013 8:16 am
Completed: The Crystal Castle
Projects: My Ninja Life
Contact:

Re: How can I customize a changeable name? [Solved]

#3 Post by Flowers from Nowhere » Sun Nov 03, 2013 2:38 pm

That works perfectly, thank you!

Post Reply

Who is online

Users browsing this forum: Google [Bot]