CREATE YOUR AI CUM SLUT ON CANDY.AI TRY FOR FREE
x

Ren'Py Main character name in a Ren Py game.

Mephistofeles

Active Member
Jul 9, 2017
688
791
How do you code a player input main character name?? I have seen different methods to do it in different sites and i would like to hear your opinions about it. And how do you define the main character as a , well, character??
 

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,131
3,195
this is how to do it here is more info


Python:
define pov = Character("[povname]")

python:
    povname = renpy.input("What is your name?", length=32)
    povname = povname.strip()

    if not povname:
         povname = "Pat Smith"

label start:
    pov "My name is [povname]!"
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,611
2,260
There's a code shortcut you can take too.

Python:
default player_name = "Unnamed"

define mc = Character("[player_name]")

label start:

    scene black with fade

    "Start:.... "

    $ player_name = renpy.input("What is your name name?", length=20)
    $ player_name = player_name.strip() or "Patrick"

    "The main character in this game is called [mc]."

    "*** THE END ***"

    return

I initially set the value to "Unnamed" just in case I accidentally use the name before the player has set it. It's unlikely, but if I ever do make that mistake, it'll be obvious to me when I play that section of the game.

The .strip() removes any leading or trailing spaces the player may have inadvertently (or deliberately) typed in. If the player didn't type anything in (or just a lot of spaces) then the result will be an empty string.

The $ (dollar sign) is just a shortcut for "do python command" and can be used instead of python: where you are only doing one or two simple lines of python.

The or "Patrick" is the shortcut I was talking about though. If the player name variable is empty at that point, it will use "Patrick" instead and avoids the need to to do the if not player_name: check.

Finally, I've used [mc] rather than [player_name] when I wanted to display the character's name as part of another string. Either will work. But it's a habit I've picked up relatively recently, since it also works with all other characters regardless of whether they are using variables as names or their names are hard coded into their Character() definition. It means that in the future, if you ever wanted to... it's easier to adapt your game to allow the player to name other characters in your game. It's quicker to type too.