Ren'Py how can I make the name of the characters customizable?

Black Ram oss

Black Ram
Game Developer
May 10, 2018
582
1,564
how can I make the name of the characters customizable?
I predated like this:
Code:
define john = Character("John", who_color="#007f1e")
    "His name is:"
    $ name = ""
    $ name = renpy.input("(Default: John)")
    $ name = name.strip()
    if name == "":
        $ john.name = "John"
    else:
        $ john.name = name
but saving by closing the game, and then loading the save the name returns John.
I also thought of saving it in an external file. but it might work in case I have two saves with different names.
I predated like this:

but saving by closing the game, and then loading the save the name returns John.
I also thought of saving it in an external file. but it might work in case I have two saves with different names.
 
  • Like
Reactions: Flower34234

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,611
2,258
This is my abbreviated version:

Python:
default mc_name = "Unknown"
default std_mc_name = "John"

define mc = Character("[mc_name]", who_color="#007f1e")

label start:

    scene black with fade

    $ mc_name = renpy.input("What is your name? {i}(Press ENTER to use the name '[std_mc_name]'){/i}", length=20)
    $ mc_name = mc_name.strip() or std_mc_name

    "Welcome [mc_name]."
    mc "Thanks."

    "*** THE END ***"

    return
I go a bit overboard by using an additional variable std_mc_name, but it makes it easier when you want to do something like importing persistent character names from previous games by the same author.

But the simple answer to your question is to put the variable within square brackets as part of the Character definition.
Using your own example...
define john = Character("[name]", who_color="#007f1e")

I would caution against using variables names like name, since "name" is a common keyword in a lot of programming languages. Probably not in RenPy... but if you run into problems, that'll be it.
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,978
16,234
As complement of what 79flavors already said :

but saving by closing the game, and then loading the save the name returns John.
A variable declared with define will not be saved unless it's value is changed.

But here, it's not the value of john that you change, but just the value of one of its attribute. Therefore, the variable stay unchanged from Ren'py's side and not saved. Which is why the name return to its default when you load a saved game.