Ren'Py Getting input to recognize previously input name?

SlutsGetFucked

New Member
Apr 3, 2022
5
1
Hello!

I am trying to get Renpy to recognize input that was previously input earlier in the game.

What I mean is: At the beginning of the game, the game asks for the player's name. For the purposes of the explanation, I'll use the default name of Ben. This is saved under the variable mc (and using [mc] works just fine throughout the game.) Later on in the game, Ben is rather unexpectedly elevated to a position of Nobility and given a servant. The player can change what the servant calls him, and I want there to be a unique line of dialogue if the player chooses to put in their name, but when I've tested it, the code keeps using the default response rather than the unique one.

The code I wrote was simple]:
Code:
elif lord == "[mc]":
            scene 100 with dis
            a "*gasp* I- I could never be so presumptuous as to call you by your name, My L-"
All of the other unique dialogues work, (Master, Daddy, the usual suspects), but I'm guessing the reason this one doesn't is because it is a name saved behind a variable, but I can't seem to figure out how to get Ren'Py to recognize that Ben is the same as the Ben stored in [mc].

I hope that makes sense, I feel like that was a bit of a convoluted way to explain it, but hopefully it's clear enough. If Ben is stored as [mc] then if the player inputs Ben again for what he wishes his servant to call him, I want there to be unique dialogue, but as things stand, typing Ben into this would result in the default dialogue.

Thanks for your help, I appreciate it!
 

peterppp

Member
Mar 5, 2020
458
864
Hello!

I am trying to get Renpy to recognize input that was previously input earlier in the game.

What I mean is: At the beginning of the game, the game asks for the player's name. For the purposes of the explanation, I'll use the default name of Ben. This is saved under the variable mc (and using [mc] works just fine throughout the game.) Later on in the game, Ben is rather unexpectedly elevated to a position of Nobility and given a servant. The player can change what the servant calls him, and I want there to be a unique line of dialogue if the player chooses to put in their name, but when I've tested it, the code keeps using the default response rather than the unique one.

The code I wrote was simple]:
Code:
elif lord == "[mc]":
            scene 100 with dis
            a "*gasp* I- I could never be so presumptuous as to call you by your name, My L-"
All of the other unique dialogues work, (Master, Daddy, the usual suspects), but I'm guessing the reason this one doesn't is because it is a name saved behind a variable, but I can't seem to figure out how to get Ren'Py to recognize that Ben is the same as the Ben stored in [mc].

I hope that makes sense, I feel like that was a bit of a convoluted way to explain it, but hopefully it's clear enough. If Ben is stored as [mc] then if the player inputs Ben again for what he wishes his servant to call him, I want there to be unique dialogue, but as things stand, typing Ben into this would result in the default dialogue.

Thanks for your help, I appreciate it!
you are comparing the lord variable with the string output of the value of mc. seems it doesn't work even for strings, and even if it did, it would be the wrong way to do it. if you want to compare the variables, simply compare them: elif lord == mc. assuming mc is not a character object in which case you must compare it with mc.name
 

MissFortune

I Was Once, Possibly, Maybe, Perhaps… A Harem King
Respected User
Game Developer
Aug 17, 2019
4,503
7,425
There's probably an easier way to do it with persistents or something of the nature.

But the easiest way would be to just ask the player. Something like:

Python:
a "What would you like us to call you?"
#Do window/qm hide shenanigans here, if you're into that.
default mctitle_nochange = False
default mctitle_change = False
menu:
    "Call me by my name."
        $ mctitle_nochange = True
        mc "Call me [mc]. Just because my title's changed doesn't mean I have."
        a "blah blah."
    "Call me. . ."
        $ mctitle_change = True
        $ ntitle = ""

        $ ntitle = renpy.input("What's your new title?")
        $ ntitle = mc_name.strip()
            if ntitle == "":
            $ ntitle = "Insert Default Name/Title Here." #make sure you define this as a character somewhere.
        ntitle "Call me [ntitle]. If feels more fitting now. A new chapter of sorts."
a "Ah, yes. I do agree."
if mctitle_nochange is True:
    a "The people already know you as you are. There's no need to create undue confusion."
else: #Or elif, if multiples.
    a "Your title has changed and people need to show you such respect."
 

SlutsGetFucked

New Member
Apr 3, 2022
5
1
you are comparing the lord variable with the string output of the value of mc. seems it doesn't work even for strings, and even if it did, it would be the wrong way to do it. if you want to compare the variables, simply compare them: elif lord == mc. assuming mc is not a character object in which case you must compare it with mc.name
Ah, it seems so obvious. That worked perfectly, thanks a bunch!
 
  • Like
Reactions: peterppp

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,111
14,790
you are comparing the lord variable with the string output of the value of mc.
Not even.
The "[variable_name]" syntax only have a meaning if the text is proceeded by Ren'Py text display process. So, he is comparing the value stored into lord with the literal string "[mc]".


if you want to compare the variables, simply compare them: elif lord == mc. assuming mc is not a character object in which case you must compare it with mc.name
Yes.
 
  • Like
Reactions: peterppp

peterppp

Member
Mar 5, 2020
458
864
Not even.
The "[variable_name]" syntax only have a meaning if the text is proceeded by Ren'Py text display process. So, he is comparing the value stored into lord with the literal string "[mc]".
that makes sense. my limited experience with how renpy works shows again. i was a bit puzzled that his code didn't work since to me it seemed to be comparing two equal string values.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,111
14,790
my limited experience with how renpy works shows again. i was a bit puzzled that his code didn't work since to me it seemed to be comparing two equal string values.
You surely aren't the only one, especially since I don't remember the doc explicitly stating that it's a purely Ren'Py thing.

It's obvious right from the starts for someone knowing Python. But I totally understand why it isn't for anyone who never used Python before, even if they have some coding knowledge. They see something like, "If you write "something [variable] another thing", the content of 'variable' will be displayed", and why shouldn't they believe that it works like that for any strings ?

This especially there's things like the "something %s other thing" % variable syntax that are also presented in Ren'Py doc. And here, it's a Python thing, so it would works in OP case.
Worse, define MC = Character( "[mc]" ) is how you make MC name be the content of the "mc" variable. And here it's really not obvious that it works because it will pass through the same process than something like sayer "My name is [mc].".
 
  • Like
Reactions: peterppp