renpy/doc/cookbook/Who's that?

From Ren'Py

Jump to: navigation, search

Who's that? Changing character names during the game

Quite often the first time a character appears in the game, the player won't know the name of the character, just that they're the "Maid" perhaps, or the "Stranger". Yet later, when the player has learned more about them, we want the game to refer to them differently.

Fortunately it's easy to do, using DynamicCharacter. We just use a placeholder (which Ren Py calls a "variable") and then change the meaning of this placeholder term when we want to.

init:
    $ millie = DynamicCharacter("maid_name")
    # we've chosen to call the variable "maid_name", but it doesn't exist yet.

label start:
    # Set "maid_name" to mean something early on in the game.
    # You don't have to use it right away.
    $ maid_name = "Maid"
    # ''now'' the variable "maid_name" exists - it's only created when you set it.

    millie "I hope you'll be comfortable here."
    millie "We always do our best to make our guests comfortable."
    millie "If you need anything, just ask for \"Millie\" - that's me."
    maid_name = "Millie"
    millie "The bell boy's just bringing your suitcases now."

The first three times that Millie speaks, she'll be identified as the "Maid", but after she's told the player her name, she'll be shown as "Millie".

For this simple example it would be just as easy to use two different Characters and switch between them after Millie has given her name. But imagine in a more complex game where Millie only gives her name if the player decides to tip her. By using DynamicCharacter, you don't have to think about whether the player chose to tip or not, the game will show "Millie" or "Maid" as appropriate.

Personal tools