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.