Player_name key error and quick menu broken (SOLVED)

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
K0torisan
Regular
Posts: 26
Joined: Fri Feb 16, 2018 10:21 pm
Contact:

Player_name key error and quick menu broken (SOLVED)

#1 Post by K0torisan »

I'll do my best to explain the problem because it is twofold.
First, I have a quick menu that is an imagemap which I've coded and works fine. The map is a stack of four buttons from top to bottom: skip, save, load, and preferences.
Both this menu and the player name work correctly when loading a past save or starting a new game.

Today I implemented a "chapter menu" that allows players to jump back to past scenes they have already read in the script. However, my quick_menu is broken when I select a past chapter. Weirdly, only the top two buttons (skip and save) are broken - the game doesn't recognize that they are buttons at all. I messed around a bit and got skip to work sometimes - but it jumped automatically to the furthest place a character is in the route rather than quickly running through all the dialogue.
I am also getting the KeyError u 'player_name" message when I come to a piece of script that is spoken by the player character.

Here is the traceback for the error:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 9473, in script
    pov "Um… What is this place?"
KeyError: u'player_name'

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 9473, in script
    pov "Um… What is this place?"
  File "/Users/sabrinaboone/Desktop/renpy-6.99.12.4-sdk/renpy/ast.py", line 624, in execute
    renpy.exports.say(who, what, interact=self.interact, *args, **kwargs)
  File "/Users/sabrinaboone/Desktop/renpy-6.99.12.4-sdk/renpy/exports.py", line 1173, in say
    who(what, *args, **kwargs)
  File "/Users/sabrinaboone/Desktop/renpy-6.99.12.4-sdk/renpy/character.py", line 889, in __call__
    who = who_pattern.replace("[who]", sub(who))
  File "/Users/sabrinaboone/Desktop/renpy-6.99.12.4-sdk/renpy/character.py", line 884, in sub
    return renpy.substitutions.substitute(s, scope=scope, force=force, translate=translate)[0]
  File "/Users/sabrinaboone/Desktop/renpy-6.99.12.4-sdk/renpy/substitutions.py", line 242, in substitute
    s = formatter.vformat(s, (), kwargs)
  File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/string.py", line 563, in vformat
  File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/string.py", line 585, in _vformat
  File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/string.py", line 646, in get_field
  File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/string.py", line 605, in get_value
KeyError: u'player_name'
I messed with my name input and changed it to this:

Code: Select all

"Please input your name."

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

$ player_name = player_name.strip()

if not player_name:
    $ player_name="Dante"
It works fine if I start the game (input name) and then go to the chapter menu to skip. I'm just not sure how to keep the name working across all save files, as when I have attempted to make it persistent, it doesn't work.

Please help! I'm really not sure what is happening. And, of course, I can copy more lines of code if necessary. Thank you!
Last edited by K0torisan on Sat Feb 24, 2018 12:33 pm, edited 1 time in total.

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

Re: Player_name key error and quick menu broken

#2 Post by rayminator »

do you have the python: above the name input part? not in less you have it somewhere else

K0torisan
Regular
Posts: 26
Joined: Fri Feb 16, 2018 10:21 pm
Contact:

Re: Player_name key error and quick menu broken

#3 Post by K0torisan »

rayminator wrote: Sat Feb 24, 2018 1:21 am do you have the python: above the name input part? not in less you have it somewhere else
I changed the code to input name:

Code: Select all

python:
        playername = renpy.input("Input your name.")
        playername = playername.strip()
        if not playername:
            playername = "Dante"
Still have the same problem. Quick menu doesn't work when scenes are accessed through the Chapter Menu and I'm still getting the KeyError message.

For the record, I used this guide to make my Chapter/Contents Menu: viewtopic.php?t=17301

K0torisan
Regular
Posts: 26
Joined: Fri Feb 16, 2018 10:21 pm
Contact:

Re: Player_name key error and quick menu broken

#4 Post by K0torisan »

Update: I've been messing with this code for at least 5 hours and at this point I'm quite irritated.

I changed my code for name input to:

Code: Select all

label set_name:
    if persistent.player == None:
        "Please input your name."
        $player_name = renpy.input("", "Dante")
        $player_name = player_name.strip()
        if player_name is not None:
            $persistent.player = player_name
I know that setting the name to persistent is annoying, but it's the only thing I could think to come up with. Unfortunately, STILL doesn't work. I'm getting the same KeyError u'player_name' message as always.

I put the code for setting the name at the very top of my game, so I can't understand what's going on. UGH. :evil:

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

Re: Player_name key error and quick menu broken

#5 Post by Ocelot »

Show how you pov character is declared.
< < insert Rick Cook quote here > >

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Player_name key error and quick menu broken

#6 Post by Remix »

First step, declare default and setup Character:

Code: Select all

default player_name = "Dante"
define pov = Character("[player_name]")
Next include the input inside a label where wanted:

Code: Select all

label start:
    "Please input your name."

    $ player_name = renpy.input("What is your name?", default='Dante', exclude='\\/`{}\'"[]()', length=18)
    $ player_name = player_name.strip()

    if not player_name:
        $ player_name="Dante"

    pov "I am [player_name] ... "
Next... check it works
Frameworks & Scriptlets:

K0torisan
Regular
Posts: 26
Joined: Fri Feb 16, 2018 10:21 pm
Contact:

Re: Player_name key error and quick menu broken

#7 Post by K0torisan »

Remix wrote: Sat Feb 24, 2018 8:15 am First step, declare default and setup Character:

Code: Select all

default player_name = "Dante"
define pov = Character("[player_name]")
Next include the input inside a label where wanted:

Code: Select all

label start:
    "Please input your name."

    $ player_name = renpy.input("What is your name?", default='Dante', exclude='\\/`{}\'"[]()', length=18)
    $ player_name = player_name.strip()

    if not player_name:
        $ player_name="Dante"

    pov "I am [player_name] ... "
Next... check it works
Thanks for your help! I got an interesting result... It works fine if I set a name and then use the chapter menu to skip in the same session. BUT...
I'm not getting the KeyError anymore, BUT the quick menu still doesn't work and the character name is set to "Dante" when I load the game and go straight to the chapter menu. I'd like for it to remember the player's name, but when I try to make the player name persistent, I get that KeyError.

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

Re: Player_name key error and quick menu broken

#8 Post by Ocelot »

Please, show your code. Remix example should work well with saving and loading.

First of all: delete all saved games. It is not a good idea to load saves from old versions in current one.
Second: make sure that you cannot skip name setting. You should not be able to do anything before setting name. KeyError happened because you tried to use player_name without setting it to anything. Your game flow should be: start → name set → chapter select.
< < insert Rick Cook quote here > >

K0torisan
Regular
Posts: 26
Joined: Fri Feb 16, 2018 10:21 pm
Contact:

Re: Player_name key error and quick menu broken

#9 Post by K0torisan »

Yet another update.
I've solved the issue with the quick menu by using the Replay function in my chapter menus, so it looks like this now:

Code: Select all

if persistent.vincent_a1s1 == True:
            hotspot (272, 249, 146, 43) action Replay("vince_a1s1")
instead of

Code: Select all

if persistent.vincent_a1s1 == True:
            hotspot (272, 249, 146, 43) action Jump("vince_a1s1")
Then, at the end of every scene (since the whole thing can be replayed) I added:

Code: Select all

$ renpy.end_replay()
BUT! The issue with player name remains. Any help making persistent work?

K0torisan
Regular
Posts: 26
Joined: Fri Feb 16, 2018 10:21 pm
Contact:

Re: Player_name key error and quick menu broken

#10 Post by K0torisan »

Ocelot wrote: Sat Feb 24, 2018 10:53 am Please, show your code. Remix example should work well with saving and loading.

First of all: delete all saved games. It is not a good idea to load saves from old versions in current one.
Second: make sure that you cannot skip name setting. You should not be able to do anything before setting name. KeyError happened because you tried to use player_name without setting it to anything. Your game flow should be: start → name set → chapter select.
I think you're misunderstanding, but I didn't really explain it well - the chapter menu isn't a part of the script, it's a screen that is accessed from navigation/main menu.
I posted the guide that I used, but here's what it looks like:

Code: Select all

screen chapter:
    tag menu
    
    #background image 
    add "ch_character_bg.png"
    
    #notsure what this does
    use navigation
    
    imagemap:
        ground "ch_character_bg_ground.png"
        idle "ch_character_bg_idle.png"
        hover "ch_character_bg_hover.png"
        
        #the buttons are transparent sooo
        alpha False
        
        hotspot (837, 190, 185, 60) action ShowMenu ("allegra_chapter")
        hotspot (178, 190, 206, 55) action ShowMenu ("vincent_chapter")
        hotspot (174, 262, 191, 52) action ShowMenu ("lucien_chapter")
        hotspot (808, 262, 208, 65) action ShowMenu ("ophelia_chapter")
Then, that screen goes to this one:

Code: Select all

screen allegra_chapter:
    tag menu
    
    add "allegra_ch_bg.png"
    
    use navigation
    
    imagemap:
        ground "AS_ch_bg_ground.png"
        idle "AS_ch_bg_idle.png"
        hover "AS_ch_bg_hover.png"
        
        if persistent.allegra_a1s1 == True:
            hotspot (272, 249, 146, 43) action Replay("all_a1s1")
        if persistent.allegra_a1s2 == True:
            hotspot (272, 299, 146, 43) action Replay("all_a1s2")
I'm not loading old saves, I was just testing to see if the quick menu worked by saving/reloading the most recent session.

I've solved the problem of the quick menu all my own. All I want to do now is make sure that the game remembers the player's name instead of using the default. Again, my attempts at making the player's name persistent have not worked and it reverts to using the default.

If you want more code than this, please be specific. I have posted above what I used for the player's name, as well as my attempt at using persistent for the player's name.

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

Re: Player_name key error and quick menu broken

#11 Post by Ocelot »

Ok. If you want persistent to work here, you must ensure that it always has value. Setting default value for persistent data is slightly different from normal variables: https://www.renpy.org/doc/html/changelo ... provements

Code: Select all

define persistent.palyer_name = 'Dante'
define pov = Character("[persistent.player_name]")
< < insert Rick Cook quote here > >

K0torisan
Regular
Posts: 26
Joined: Fri Feb 16, 2018 10:21 pm
Contact:

Re: Player_name key error and quick menu broken

#12 Post by K0torisan »

Ocelot wrote: Sat Feb 24, 2018 12:23 pm Ok. If you want persistent to work here, you must ensure that it always has value. Setting default value for persistent data is slightly different from normal variables: https://www.renpy.org/doc/html/changelo ... provements

Code: Select all

define persistent.palyer_name = 'Dante'
define pov = Character("[persistent.player_name]")
AHHH Thank you, it works!!

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], dragondatingsim, Google [Bot]