Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
-
lsf22
- Regular
- Posts: 98
- Joined: Wed Feb 23, 2022 9:43 pm
-
Contact:
#1
Post
by lsf22 » Sun Aug 07, 2022 2:04 am
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
-
m_from_space
- Veteran
- Posts: 302
- Joined: Sun Feb 21, 2021 3:36 am
-
Contact:
#2
Post
by m_from_space » 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.
-
lsf22
- Regular
- Posts: 98
- Joined: Wed Feb 23, 2022 9:43 pm
-
Contact:
#3
Post
by lsf22 » Sun Aug 07, 2022 2:21 am
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
-
m_from_space
- Veteran
- Posts: 302
- Joined: Sun Feb 21, 2021 3:36 am
-
Contact:
#4
Post
by m_from_space » 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?
-
lsf22
- Regular
- Posts: 98
- Joined: Wed Feb 23, 2022 9:43 pm
-
Contact:
#5
Post
by lsf22 » Sun Aug 07, 2022 2:48 am
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
-
Ocelot
- Eileen-Class Veteran
- Posts: 1883
- Joined: Tue Aug 23, 2016 10:35 am
- Github: MiiNiPaa
- Discord: MiiNiPaa#4384
-
Contact:
#6
Post
by Ocelot » Sun Aug 07, 2022 2:59 am
Do you use define or default fo main_character_name? Isthere anything setting main_character_name to some predefined value when you enter replay?
< < insert Rick Cook quote here > >
-
lsf22
- Regular
- Posts: 98
- Joined: Wed Feb 23, 2022 9:43 pm
-
Contact:
#7
Post
by lsf22 » Sun Aug 07, 2022 3:09 am
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
-
enaielei
- Regular
- Posts: 114
- Joined: Fri Sep 17, 2021 2:09 am
- Tumblr: enaielei
- Deviantart: enaielei
- Github: enaielei
- Skype: enaielei
- Soundcloud: enaielei
- itch: enaielei
- Discord: enaielei#7487
-
Contact:
#8
Post
by enaielei » 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")
-
Ocelot
- Eileen-Class Veteran
- Posts: 1883
- Joined: Tue Aug 23, 2016 10:35 am
- Github: MiiNiPaa
- Discord: MiiNiPaa#4384
-
Contact:
#9
Post
by Ocelot » 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.
< < insert Rick Cook quote here > >
-
lsf22
- Regular
- Posts: 98
- Joined: Wed Feb 23, 2022 9:43 pm
-
Contact:
#10
Post
by lsf22 » Sun Aug 07, 2022 3:30 am
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?
-
lsf22
- Regular
- Posts: 98
- Joined: Wed Feb 23, 2022 9:43 pm
-
Contact:
#11
Post
by lsf22 » Sun Aug 07, 2022 3:31 am
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?
-
lsf22
- Regular
- Posts: 98
- Joined: Wed Feb 23, 2022 9:43 pm
-
Contact:
#12
Post
by lsf22 » Sun Aug 07, 2022 3:38 am
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.
Users browsing this forum: No registered users