I'm not sure if the above code would work since 1) it'd require an instance of the object to work, 2) the original logic doesn't make sense anyway
OP:
You have created a condition where if someone puts in the same name, THEN choose no to renaming the character, would trigger a reset of new name and old name (even though the new name is already the same as the old name), and then stop allowing player to change the name. That makes no sense - if player chooses No to accepting the the name change, the should be given the opportunity to try again. So the logic doesn't make sense to me. It'd make more sense if you put that condition in the Yes choice if someone chooses the exact same name.
Also you're trying to use recursion (calling your own function again) if player chooses No, that's a bad idea for something that could in theory goes on infinitely. Recursion should only be done to things that as a finite depth / bottom or it can crash your program when the computer runs out of resources remembering all the instances of a recursion being run.
So, may I recommend you use a label in place of a class to do the whole thing, and use a loop instead of recursion? I don't know how you actually hold your character's names, so I've created a Char() class that holds it for this example, you need to change it so it's relevant to your own character classes:
Code: Select all
label name_change(character):
$ renpy.dynamic("new_name", "loop") # declare local variables
$ loop = True
$ new_name = "" # prevent key error on quit
while loop:
$ new_name = renpy.input("What do you want to change [character.name]'s name to?").strip()
menu:
"Do you want to rename [character.name] to [new_name]?"
"Yes":
$ loop = False # this ends the loop
"[character.name]'s name is now [new_name]"
$ character.name = new_name
"No":
pass # this will repeat the loop
return
init python:
class Char:
def __init__(self, name):
self.name = name
label start:
$ eileen = Char("Eileen")
call name_change(eileen)
"End"
return