Ren'Py persistant names

recreation

pure evil!
Respected User
Game Developer
Jun 10, 2018
6,327
22,773
Hey :)
I try to make a new starting point from the main menu (something like New Game+) and want to use mcs name from the previous play though.
Simplyfied:
Python:
define pc = Character("[pc_name]")
define pcsure = Character("[pcsure]")
   ...

label start:
    ...
    $ pc_name = renpy.input("Choose your first name.")
    $ pcsure = renpy.input("Choose your last name.")
...
    if pc_name == "":
        $ pc_name = "John"
    if pcsure == "":
        $ pcsure = "Doe"
    $ persistent.pc_name = pc_name
    $ persistent.pcsure = pcsure
    

    
label start_again:
    scene black with dissolve
    m "Hello [pc] [pcsure], this is a test!"
and get this:
You don't have permission to view the spoiler content. Log in or register now.
I can't figure it out and before I spend hours searching again, I'll ask directly this time^^
 

Porcus Dev

Engaged Member
Game Developer
Oct 12, 2017
2,582
4,705
Maybe this can help, though I haven't been able to prove it:

Code:
default pc = Character("John")
default pcsure = Character("Doe")

label start:

     init python:
        def input_name(character):

            new_name = renpy.input("Choose your first name")
            new_sure = renpy.input("Choose your last name")

            new_name = new_name.strip()
            new_sure = new_sure.strip()

            if not new_name:
                pass
            else:
               character.name = new_name

            if not new_sure:
                pass
            else:
                character.name = new_sure

     $ input_name(pc)
     $ input_sure(pcsure)

label start_again:
     scene black with dissolve
     "Hello [pc.name] [pcsure.sure], this is a test."
NOTE: Use "default" instead of "define" so that names are loaded again when loading a save file.
 

Porcus Dev

Engaged Member
Game Developer
Oct 12, 2017
2,582
4,705
Above I have tried to adapt my code to your needs, but I don't use last name, so I leave you here below my code for you to look at, because maybe I have not adapted it well :p

Code:
default t = Character("Tony")


label start:

    init python:
        player = Player("Tony")
       
        def input_name(character):
           
            new_name = renpy.input("What is your name?", length=15)
           
            new_name = new_name.strip()

            if not new_name:
                pass
            else:
                character.name = new_name


     t "¡Hi! My name is [t.name], but you can change it..."
     $ input_name(t)
     t "Now my name's [t.name], sounds good, huh?"
 

recreation

pure evil!
Respected User
Game Developer
Jun 10, 2018
6,327
22,773
@mgomez0077 Not really what I was asking for, but you gave me an idea :p
Ther persistant data was stored but wasn't there, so I though i'd load it extra and added:
Python:
    $ pc_name = persistent.pc_name
    $ pc_sure = persistent.pc_sure
to:
Python:
label start_again:
    scene black with dissolve
    m "Hello [pc] [pcsure], this is a test!"
and it works, so thx :)
Python:
label start_again:
    $ pc_name = persistent.pc_name
    $ pc_sure = persistent.pc_sure
    scene black with dissolve
    m "Hello [pc] [pcsure], this is a test!"
 
  • Like
Reactions: Porcus Dev

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,607
2,256
You could take it one stage further and use to have a common name for all "your" games.
Right now, that could be just one. But eventually, all your future games could have persistent names.

Maybe have something where you have the usual "Enter your name (press <ENTER> for the default name 'Bob')", but instead of hardcoding 'Bob' in there, pick up the name from the Multi Game Persistent data. If there's no persistent name, THEN default to 'Bob'.

Then whatever name you enter, store that name in the Multi Game Persistent data... for either your next play-through... or the next game.

I'd have to have a mess to come up with some example code, but you probably don't need to do that for you - now I've planted the idea in your head. Shout me if you want some working example code, and I'll see what I can cobble together.

You don't have permission to view the spoiler content. Log in or register now.
 

Rich

Old Fart
Modder
Donor
Respected User
Game Developer
Jun 25, 2017
2,566
7,378
Obviously, just make sure you handle the case where persistent.pc_name and persistent.pc_sure aren't defined. (If the player has never run the game before, they will both have the value None.)

You can simulate that case by deleting your persistent data and then starting the game.

(You probably know that already, but always good to leave breadcrumbs for others who stumble on the thread.)
 

recreation

pure evil!
Respected User
Game Developer
Jun 10, 2018
6,327
22,773
You could take it one stage further and use to have a common name for all "your" games.
Right now, that could be just one. But eventually, all your future games could have persistent names.
Yeah I've stumbled over multipersistent a few times. It's a nice thing for addons or follow ups.

(You probably know that already, but always good to leave breadcrumbs for others who stumble on the thread.)
Yes, I made a check if the persistent data is set. It get's set at the end of the game and until it is not set, the menu entry won't show up (maybe I let it show up, but greyed out and make it unclickable) :)
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,959
16,193
Ther persistant data was stored but wasn't there, so I though i'd load it extra and added:
Python:
    $ pc_name = persistent.pc_name
    $ pc_sure = persistent.pc_sure
persistent is to be seen as a store (or as an object if it's easier to understand). While your initial error was apparently to think that it acted like some kind of flags. Something like the difference between persistent pc_name = "something" and store.pc_name = "something".

The code you want looks more like this :
Python:
# You aren't limited to straight variables here.
define pc = Character("[persistent.pc_name]")

label startX:

    # Prompt only if not defined yet.
    if persistent.pc_name is None:
        # And store directly where needed.
        $ persistent.pc_name = renpy.input("Choose your first name.").strip()

    [...]
 
  • Like
Reactions: recreation

recreation

pure evil!
Respected User
Game Developer
Jun 10, 2018
6,327
22,773
persistent is to be seen as a store (or as an object if it's easier to understand). While your initial error was apparently to think that it acted like some kind of flags. Something like the difference between persistent pc_name = "something" and store.pc_name = "something".

The code you want looks more like this :
Python:
# You aren't limited to straight variables here.
define pc = Character("[persistent.pc_name]")

label startX:

    # Prompt only if not defined yet.
    if persistent.pc_name is None:
        # And store directly where needed.
        $ persistent.pc_name = renpy.input("Choose your first name.").strip()

    [...]
This wouldn't work the way I need it. I want to reuse the name given in the first playthrough, but I don't want to have the player to reuse the name if they decide to start a new game.
I think it would be more like this:
Python:
label start:
    $ pc_name = renpy.input("Choose your first name.").strip()
    if pc_name == "":
        if persistent.pc_name is not none:
            $ pc_name = persistent.pc_name
        else:
            $ pc_name = "John"
            $ persistent.pc_name = pc_name
btw would this work in python?:
Python:
if strip(persistent.pc_name) is not none:
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,959
16,193
I want to reuse the name given in the first playthrough, but I don't want to have the player to reuse the name if they decide to start a new game.
Python:
screen navigation():
        [...]
        if main_menu:

            textbutton _("Start") action Start()
            textbutton _("Start+") action Jump( "startPlus" )
        else:
        [...]

label startPlus:
    if persistent.pc_name is None:
        # And store directly where needed.
        $ persistent.pc_name = renpy.input("Choose your first name.").strip()
this ?




btw would this work in python?:
Python:
if strip(persistent.pc_name) is not none:
No for three reasons (well, in fact two) :
  1. strip is a method of the String object not a function ;
  2. If it was a function, if would have raised an exception because None isn't a string, and so can't be striped ;
  3. "none" is a variable, while None is the null value.
 

recreation

pure evil!
Respected User
Game Developer
Jun 10, 2018
6,327
22,773
Python:
screen navigation():
        [...]
        if main_menu:

            textbutton _("Start") action Start()
            textbutton _("Start+") action Jump( "startPlus" )
        else:
        [...]

label startPlus:
    if persistent.pc_name is None:
        # And store directly where needed.
        $ persistent.pc_name = renpy.input("Choose your first name.").strip()
this ?
close:
Python:
        if main_menu:

            textbutton _("Start") action Start()
            if persistent.endGame: #will be set in the last scene of the story
                textbutton _("New Game+") action Start("start_again")
The player can choose the name only in the normal "Start game", but not in the new game+:
Python:
label start:
    $ pc_name = renpy.input("Choose your first name.").strip()
    if pc_name == "": # if player doesn't care to type a name...
        if persistent.pc_name is not none: #check if there is a persistent name already and use it
            $ pc_name = persistent.pc_name
        else:
            $ pc_name = "John"
            $ persistent.pc_name = pc_name
    else
        persisitent.pc_name = pc_name

label start_again:
    $pc_name = persistent.pc_name