KeyError: u'p' (but with odd-ish circumstances)

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.
Post Reply
Message
Author
catskulls
Newbie
Posts: 3
Joined: Sat Nov 27, 2021 8:46 am
itch: catskullspng
Discord: catskulls#7257
Contact:

KeyError: u'p' (but with odd-ish circumstances)

#1 Post by catskulls »

Hey folks!
As the subject title suggests, I've been having problems with KeyError: u'p'. But due to the odd concept of my game, I haven't been able to find help online. That'll probably be an easy fix, but hey, I'm a total newbie at this!

To sum up this part of my game, there's no concept of save slots or a linear story. The idea is that you boot up the game the first time, enter your name, go through a sort of intro and then after that, every time you reboot the game you start at a certain point and your name has already been entered.

Here's my code so far:

Code: Select all


define c = Character("Nell")
define name = Character('[p]')
define persistent.introscene = 0

label start:

    $_game_menu_screen = None

    if persistent.introscene:

         jump chatbase


label intro:
    
    show nell idle

    c "Hey there."
    c "My name is Nell, it's very nice to meet you."
    c "I'd love to get to know you, what's your name?"

    $ p = renpy.input("What is your name?").strip()

    c "[p]? Okay!"

    $ persistent.introscene = 1

label chatbase:

    c "Hello, [p]!"
And that's where my error comes in.

Any tips on solving this? Sorry for being such a newbie!
Cheers

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2384
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: KeyError: u'p' (but with odd-ish circumstances)

#2 Post by Ocelot »

Your problem that you are not saving your name anywhere. So, after you complete introm you will jump over intro, and you will not enter any information into p variable.

Either look into single-save model (autosave game at certain points and load it on start), or store variables you need to keep between sessions in persistent storage.
< < insert Rick Cook quote here > >

rayminator
Miko-Class Veteran
Posts: 793
Joined: Fri Feb 09, 2018 12:05 am
Location: Canada
Contact:

Re: KeyError: u'p' (but with odd-ish circumstances)

#3 Post by rayminator »

take a look at this
https://www.renpy.org/doc/html/input.html

it's either you didn't understand when I said not to use p
in your last question you had it like this

Code: Select all

define p = Character('[p]')
this should work
example:

Code: Select all

define pov = Character("[povname]")


python:
    povname = renpy.input("What is your name?", length=32)
    povname = povname.strip()

    if not povname:
         povname = "Pat Smith"

pov "My name is [povname]!"

Post Reply

Who is online

Users browsing this forum: Zodiac_Stories