Characters

Instead of repeatedly typing out "Alice" we can define her as a character. Doing anything repeatedly is error-prone ("Alcie" will happen!), and like good programmers we should avoid it for that reason alone. At least this way there will be an error at run-time rather than a typo that might never get spotted.


define   alice = Character("Alice")

label downTheRabbitHole:
    "Alice was beginning to get very tired of sitting by her sister on the bank,
    and of having nothing to do: once or twice she had peeped into the book her
    sister was reading, but it had no pictures or conversations in it."
    
    alice "What is the use of a book without pictures or conversations?"
    return

What's going on here?

The define statement is run at init-time (before the "Start" button is pressed by the player) and creates a "constant" called alice that can be used in place of the string we had before.

But what's really going on here?

The Character(...) is a Python function that takes the parameters we pass it and creates an object to represent Alice in dialogue. In this case the object is an ADVCharacter [1] that carries all sorts of attributes that control how Alice's dialogue appears.

For example we can change the colour of Alice's dialogue from the default highlight colour chosen when creating the game by changing the definition like this:


define   alice = Character("Alice", color="#569CD6")

Special characters

Ren'Py defines a number of special pre-built characters . Changing or redefining these should be done with caution.

CharacterFunction
adv The base kind of character where one line is displayed on the screen at a time.
alt A useable narrator style character whose text only displays (and is voiced) when self-voicing is on.
centered A useable narrator style character whose text displays in the centre of the screen instead of the say box.
extend A useable special character that can be used to continue the dialogue of the last character. This can be used with text markup to change other things on the screen part-way through dialogue.
name_only When who is speaking is given by a string literal a temporary copy of this base character is used.
narrator The character used to display narration.
nvl The base kind of NVL character where multiple lines are displayed on the screen at a time.
vcentered A narrator style character whose text displays vertically in the centre of the screen instead of the say box.

Character store

When a say statement is used Ren'Py first looks for the character in the character named store before it looks in the normal renpy.store named store. If you define your characters in this store you can also have a normal variable of the same name:


define   character.alice = Character("Alice")
default  alice           = Npc() # Npc object for Alice

Getting organised

A typical Visual Novel has multiple characters, so it makes sense to keep all their definitions together. They could all go at the start of script.rpy, but as previously discussed that's not the best plan as there are circumstances where it can be overwritten. A better idea is to have a separate file just for character definitions such as characters.rpy. Though you can call yours dramatisPersonae.rpy or anything else if you wish. You can add comments in this file to record any author's notes you have about the characters.

Opinion

Despite it being advised in the getting started guide , I'd recommend not giving your characters single letter definitions. There are some obvious problems, such as two characters having names that start with the same letter, and some less obvious ones, such as it being really hard to search for all a character's dialogue. Modern code editors with auto-complete remove the tedium of typing eileen instead of e for each line of dialogue.
See Naming conventions

There's also an argument to be made for naming these character "constants" after their role in the story (e.g. "barman", "smith", "thief",...) rather than the character's name. You wouldn't be the first author who decides to rename one of their characters part way through writing a story ** cough, Douglas Adams, cough **. A character can be used with Ren'Py's text interpolation to display the name of the character:


define   barman = Character("Fabio")
define   smith  = Character("Gus")

label pub:
    barman "What would you like [smith]? Your usual?"
    return

Fabio
What would you like Gus? Your usual?