Naming the Player Character

There are a number of good reasons to allow the player to name the character they will be playing. The main one being that they will find it easier to play that character. However it also comes with challenges:

This will need a character definition for the PC, a list of names they can't pick, and a variable to hold their current name. Feel free to split these declarations into your various files:


define  pc          = Character("[pcName]")         # The player character
define  npcNames    = ["Diana", "Eileen", "Susan"]  # Names the PC can't choose
default pcName      = "You"                         # What to call the PC

By using Ren'Py's text substitution in the who part of the character it can change once the player picks a name for their character.

Next, add this (or similar) to get the player's input and change pcName:


    # Allow the player to pick their character's name.
    #
label pickName:
    $ renpy.dynamic('done', 'name', 'prompt')
    $ done = False
    while not done:
        $ prompt = "What is your given name?"
        $ prompt += " Type in your name, or just press <Enter> to be Erin."
        $ name = renpy.input(prompt, length=16, exclude=' ').strip().capitalize() or "Erin"
        if name in npcNames:
            "
            There's another person in this game called [name].
            Please choose a different name for yourself.
            "
        else:
            $ done = True
    $ pcName = name
    return

Local variables are used for done, name, and prompt so as not to perturb the calling code. A while loop is used so the question can be repeated until the player makes a good choice. On the renpy.input  the name length is limited, and no space characters are allowed. Whatever is entered is given an initial capital. If nothing is entered it is replaced with a default "Erin". The name is then checked against a list of other NPC names. If it is a match it is rejected with a suitable message. Finally the chosen "good" name is assigned to pcName.

Example

Here's an example use. A none to subtle hint is given that the player is naming a character who appears female in this example game. It can be disconcerting to have the player name a character before they know what gender they appear as.


    "Barkeep" "And who might you be girl?"
    call pickName
    pc "I'm [pcName] and I don't like being called a girl thank you."