Page 1 of 1
Named Character results in key error
Posted: Sun Aug 07, 2022 2:04 am
by lsf22
Ren'py version: 8.0.1
I have a named/blank slate character that runs fine in the game but when it comes to gallery replays I get the "
Key Error" stemming from the name.
my script file looks like this:
Code: Select all
define MainC = Character("[main_character_name]", color="#590000")
Code: Select all
label start: # Where the game starts #Name your character here
$ main_character_name = renpy.input("What do you want to name your main character?", default = "Zero", exclude='\\/`{}\'"[]()')
$ main_character_name = main_character_name.strip()
if main_character_name == "":
$ main_character_name = "Zero"
"Your character has been named [MainC]"
When the replay gets to the parts that have the
[MainC] that is when it brings up the
error screen
Re: Named Character results in key error
Posted: Sun Aug 07, 2022 2:10 am
by m_from_space
Try:
Code: Select all
define MainC = Character("[main_character_name]", color="#590000", dynamic=True)
and
Code: Select all
"Your character has been named [main_character_name]."
"MainC" is an object, that cannot be displayed as a string.
Re: Named Character results in key error
Posted: Sun Aug 07, 2022 2:21 am
by lsf22
m_from_space wrote: ↑Sun Aug 07, 2022 2:10 am
Try:
Code: Select all
define MainC = Character("[main_character_name]", color="#590000", dynamic=True)
and
Code: Select all
"Your character has been named [main_character_name]."
"MainC" is an object, that cannot be displayed as a string.
I went ahead and made those changes but I still get a "
KeyError" for main_character_name
Re: Named Character results in key error
Posted: Sun Aug 07, 2022 2:34 am
by m_from_space
Well it doesn't make sense. Do you use this variable elsewhere? Did you properly reload the game? Can you post the error message?
Re: Named Character results in key error
Posted: Sun Aug 07, 2022 2:48 am
by lsf22
m_from_space wrote: ↑Sun Aug 07, 2022 2:34 am
Well it doesn't make sense. Do you use this variable elsewhere? Did you properly reload the game? Can you post the error message?
Code: Select all
I'm sorry, but an uncaught exception occurred.
While running game code:
File "game/script.rpy", line 95, in script
"You are [main_character_name], a wanderer"
KeyError: 'main_character_name'
Linux-5.4.0-122-generic-x86_64-with-glibc2.31 x86_64
Ren'Py 8.0.1.22070801
Re: Named Character results in key error
Posted: Sun Aug 07, 2022 2:59 am
by Ocelot
Do you use define or default fo main_character_name? Isthere anything setting main_character_name to some predefined value when you enter replay?
Re: Named Character results in key error
Posted: Sun Aug 07, 2022 3:09 am
by lsf22
In the instance that I tested I used a default name instead of inputting one for the character. I've messed around with it and this is what it looks like now. I ended up taking off the excluding arguments after it still failed.
Code: Select all
# script file
define Mc = Character("[main_character_name]", color="#590000", dynamic=True)
############################################################################
label start: # Where the game starts # Name character here
$ main_character_name = renpy.input("What do you want to name your main character?", default = "Zero")
$ main_character_name = main_character_name.strip()
if main_character_name == "":
$ main_character_name = "Zero"
"Your character is named [main_character_name]"
Then it goes to another label point where the player can choose to skip a intro or enable a easy mode
Re: Named Character results in key error
Posted: Sun Aug 07, 2022 3:19 am
by enaielei
Remove the [ and ] in your define mc. If you marked the Character dynamic then treat the name as a python expression.
In short, either of these two would work in making the name dynamic.
Code: Select all
# Always "default" your variable then change the value later on inside your label etc.
default main_character_name = ""
define Mc = Character("main_character_name", color="#590000", dynamic=True)
define Mcc = Character("[main_character_name]", color="#590000")
Re: Named Character results in key error
Posted: Sun Aug 07, 2022 3:25 am
by Ocelot
If this is the only place where main_character_name is defined, then the error is expected: replays do not execute thelabel start, so the main_character_name variable is never set. Accessing nonexisting variable is an error.
Re: Named Character results in key error
Posted: Sun Aug 07, 2022 3:30 am
by lsf22
Ocelot wrote: ↑Sun Aug 07, 2022 3:25 am
If this is the
only place where main_character_name is defined, then the error is expected: replays do not execute thelabel start, so the main_character_name variable is never set. Accessing nonexisting variable is an error.
Does it it need it's own label where I define the Main Character (Mc)? If so should it be right after the start label?
Re: Named Character results in key error
Posted: Sun Aug 07, 2022 3:31 am
by lsf22
enaielei wrote: ↑Sun Aug 07, 2022 3:19 am
Remove the [ and ] in your define mc. If you marked the Character dynamic then treat the name as a python expression.
In short, either of these two would work in making the name dynamic.
Code: Select all
# Always "default" your variable then change the value later on inside your label etc.
default main_character_name = ""
define Mc = Character("main_character_name", color="#590000", dynamic=True)
define Mcc = Character("[main_character_name]", color="#590000")
Remove the [and] from where?
Re: Named Character results in key error
Posted: Sun Aug 07, 2022 3:38 am
by lsf22
Okay I think I got it to work now. The game and the gallery replays work now by being able to view them and see the default name for the mc in the replay gallery dialogue.