[SOLVED]Strange problem with achievements

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
User avatar
Bruni Multimedia
Regular
Posts: 114
Joined: Mon May 15, 2017 12:23 pm
Projects: Yomi Alliance
Organization: Bruni Multimedia
itch: brunimultimedia
Contact:

[SOLVED]Strange problem with achievements

#1 Post by Bruni Multimedia »

Hi. I'm developing achievements in my game. When I started it all went smoothly, however when I began adding them to the game the players always get an error:

Code: Select all

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

Full traceback:
  File "game/main.rpy", line 1355, in script call
    call events_run_period from _call_events_run_period
  File "game/event_dispatcher.rpy", line 297, in script call
    call expression _event from call_expression_event_1
  File "game/main.rpy", line 1355, in script call
    call events_run_period from _call_events_run_period
  File "game/event_dispatcher.rpy", line 297, in script call
    call expression _event from call_expression_event_1
  File "game/main.rpy", line 1377, in script call
    call events_run_period from _call_events_run_period_1
  File "game/event_dispatcher.rpy", line 297, in script call
    call expression _event from call_expression_event_1
  File "game/main.rpy", line 1391, in script call
    call events_run_period from _call_events_run_period_2
  File "game/event_dispatcher.rpy", line 297, in script call
    call expression _event from call_expression_event_1
  File "game/main.rpy", line 1377, in script call
    call events_run_period from _call_events_run_period_1
  File "game/event_dispatcher.rpy", line 297, in script call
    call expression _event from call_expression_event_1
  File "game/main.rpy", line 1355, in script call
    call events_run_period from _call_events_run_period
  File "game/event_dispatcher.rpy", line 297, in script call
    call expression _event from call_expression_event_1
  File "game/main.rpy", line 1391, in script call
    call events_run_period from _call_events_run_period_2
  File "game/event_dispatcher.rpy", line 297, in script call
    call expression _event from call_expression_event_1
  File "game/main.rpy", line 1355, in script call
    call events_run_period from _call_events_run_period
  File "game/event_dispatcher.rpy", line 297, in script call
    call expression _event from call_expression_event_1
  File "game/kiko_1.rpy", line 903, in script
    $ get_achievement("Kiko_Completed", trans=achievement_transform)
  File "C:\Users\\Downloads\GAMES\General_Practitioner-0.0.5c-pc\General_Practitioner-0.0.5c-pc\renpy\ast.py", line 814, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "C:\Users\\Downloads\GAMES\General_Practitioner-0.0.5c-pc\General_Practitioner-0.0.5c-pc\renpy\python.py", line 1719, in py_exec_bytecode
    exec bytecode in globals, locals
  File "game/kiko_1.rpy", line 903, in <module>
    $ get_achievement("Kiko_Completed", trans=achievement_transform)
  File "game/achievement.rpy", line 66, in get_achievement
    ach = persistent.achievements_dict[ach_id]
KeyError: u'KikoCompleted'
I don't get this error on my pc. I always delete "persistent" when adding achievements and told the players to do the same in their save folders. It works for me, it doesn't for them...

What am I doing wrong?
Last edited by Bruni Multimedia on Sat Dec 02, 2017 8:11 pm, edited 2 times in total.

User avatar
Bruni Multimedia
Regular
Posts: 114
Joined: Mon May 15, 2017 12:23 pm
Projects: Yomi Alliance
Organization: Bruni Multimedia
itch: brunimultimedia
Contact:

Re: Strange problem with achievements

#2 Post by Bruni Multimedia »

This is the code I'm using:

Code: Select all

transform achievement_transform:
    on show:
        xalign .98 
        yalign -.3 
        linear 0.4 xalign .98 yalign .02
    on hide:
        linear 0.4 xalign 1.9 yalign .02

screen scr_achievement_get(title, a_text, icon, trans=achievement_transform):
    timer 4.0 action Hide("scr_achievement_get")
    window:
        at trans
        background "#333333cc"
        xalign .98
        yalign .02
        xysize (450, 100)
        hbox:
            vbox:
                spacing 10
                image icon
            vbox:
                xoffset 10
                xsize 330
                text title:
                    size 22
                    id title
                text a_text:
                    size 14
                    id a_text

screen scr_achievement_update(title, a_text, icon, cur_prog, max_prog, trans=achievement_transform):
    timer 4.0 action Hide("scr_achievement_update")
    window:
        at trans
        background "#333333cc"
        xalign .98
        yalign .02
        xysize (450, 100)

        #

        hbox:
            vbox:
                spacing 10
                image icon
                text "{0}/{1}".format(cur_prog, max_prog):
                    xcenter 0.5 
                    ycenter 0.2
            vbox:
                xoffset 10
                xsize 330
                text title:
                    size 22
                    id title
                text a_text:
                    size 14
                    id a_text


                



init python:
    def get_achievement(ach_id, trans=achievement_transform):
        ach = persistent.achievements_dict[ach_id]
        achievement.grant(ach_id)
        renpy.show_screen(_screen_name='scr_achievement_get', title=ach['title'],
                          a_text=ach['text'], icon=ach['icon'], trans=trans)

    def update_achievement(ach_id, to_add=1, trans=achievement_transform):
        persistent.achievements_dict[ach_id]["cur_prog"] += to_add
        ach = persistent.achievements_dict[ach_id]

        achievement.progress(ach_id, to_add)
        if ach['cur_prog'] > ach['max_prog']:
            persistent.achievements_dict[ach_id]["cur_prog"] = ach['max_prog']
            ach = persistent.achievements_dict[ach_id]

        renpy.show_screen(_screen_name='scr_achievement_update', title=ach['title'], a_text=ach['text'],
                          icon=ach['icon'], cur_prog=ach['cur_prog'], max_prog=ach['max_prog'], trans=trans)





    # Define your achievements here
    if not persistent.achievements_dict:
        persistent.achievements_dict = {"General_Practitioner": {"type": 0, # One time achievent
                                                             "title": "General Practitioner", # Also neame for steam
                                                             "text": "You've been assigned a clinic of your own!", # description
                                                             "icon": "images/achi/gp.png" # 96x96 image
                                                             },
                                        "Rita_Completed": {"type": 0, # One time achievent
                                                             "title": "Job Certification", # Also neame for steam
                                                             "text": "You completed Rita's exam!", # description
                                                             "icon": "images/achi/rita.png" # 96x96 image
                                                             },
                                        "Clara_Completed": {"type": 0, # One time achievent
                                                             "title": "Gaining her trust", # Also neame for steam
                                                             "text": "You completed Clara's exam!", # description
                                                             "icon": "images/achi/clara.png" # 96x96 image
                                                             },
                                        "Anne_Completed": {"type": 0, # One time achievent
                                                             "title": "Emergency Situation", # Also neame for steam
                                                             "text": "You completed Anne's exam!", # description
                                                             "icon": "images/achi/anne.png" # 96x96 image
                                                             },
                                        "Paul_Completed": {"type": 0, # One time achievent
                                                             "title": "Apprehensive Parent", # Also neame for steam
                                                             "text": "You completed Paul's exam!", # description
                                                             "icon": "images/achi/paul.png" # 96x96 image
                                                             },
                                        "Robyn_Completed": {"type": 0, # One time achievent
                                                             "title": "Troublesome Brother", # Also neame for steam
                                                             "text": "You completed Robyn's exam!", # description
                                                             "icon": "images/achi/paul.png" # 96x96 image
                                                             },
                                        "Monique_Completed": {"type": 0, # One time achievent
                                                             "title": "Red eye", # Also neame for steam
                                                             "text": "You completed Monique's exam!", # description
                                                             "icon": "images/achi/gp.png" # 96x96 image
                                                             }, 
                                        "Karen_Completed": {"type": 0, # One time achievent
                                                             "title": "Sawbones", # Also neame for steam
                                                             "text": "You completed Karen's exam!", # description
                                                             "icon": "images/achi/gp.png" # 96x96 image
                                                             },
                                        "TIC": {"type": 0, # One time achievent
                                                             "title": "Two's a couple", # Also neame for steam
                                                             "text": "You found a girlfriend!", # description
                                                             "icon": "images/achi/gp.png" # 96x96 image
                                                             },
                                        "Voyeur": {"type": 0, # One time achievent
                                                             "title": "Voyeur", # Also neame for steam
                                                             "text": "You spied on your relative.", # description
                                                             "icon": "images/achi/gp.png" # 96x96 image
                                                             },    
                                        "Cruel": {"type": 0, # One time achievent
                                                             "title": "Cruel", # Also neame for steam
                                                             "text": "You broke your niece's heart.", # description
                                                             "icon": "images/achi/gp.png" # 96x96 image
                                                             },    
                                        "Uncle": {"type": 0, # One time achievent
                                                             "title": "Uncle", # Also neame for steam
                                                             "text": "You encouraged your niece to be a singer.", # description
                                                             "icon": "images/achi/gp.png" # 96x96 image
                                                             },  
                                        "Athletic": {"type": 0, # One time achievent
                                                             "title": "Athletic", # Also neame for steam
                                                             "text": "You visited the pool/gym.", # description
                                                             "icon": "images/achi/gp.png" # 96x96 image
                                                             },  
                                        "Devout": {"type": 0, # One time achievent
                                                             "title": "Devout", # Also neame for steam
                                                             "text": "You visited the church.", # description
                                                             "icon": "images/achi/gp.png" # 96x96 image
                                                             },  
                                        "Workaholic": {"type": 0, # One time achievent
                                                             "title": "Workaholic", # Also neame for steam
                                                             "text": "You accepted Dr. Richard's offer.", # description
                                                             "icon": "images/achi/gp.png" # 96x96 image
                                                             }, 
                                        "TTS": {"type": 0, # One time achievent
                                                             "title": "Trip to Seattle", # Also neame for steam
                                                             "text": "You attended the medical symposium in Seattle.", # description
                                                             "icon": "images/achi/gp.png" # 96x96 image
                                                             },  
                                        "Family_Time": {"type": 0, # One time achievent
                                                             "title": "Family Time", # Also neame for steam
                                                             "text": "You completed your [rel_typemin] visit storyline.", # description
                                                             "icon": "images/achi/gp.png" # 96x96 image
                                                             },  
                                        "Rocco": {"type": 0, # One time achievent
                                                             "title": "Rocco", # Also neame for steam
                                                             "text": "You had sex.", # description
                                                             "icon": "images/achi/rocco.png" # 96x96 image
                                                             },  
                                        "NCPD": {"type": 0, # One time achievent
                                                             "title": "Non c'è cosa più divina...", # Also neame for steam
                                                             "text": "You had sex with your cousin.", # description
                                                             "icon": "images/achi/gp.png" # 96x96 image
                                                             }, 
                                        "Kingslayer": {"type": 0, # One time achievent
                                                             "title": "Kingslayer", # Also neame for steam
                                                             "text": "You had sex with your sister.", # description
                                                             "icon": "images/achi/gp.png" # 96x96 image
                                                             },                         
                                        "Entrepreneur": {"type": 0, # One time achievent
                                                             "title": "Entrepreneur", # Also neame for steam
                                                             "text": "You hired a new staff member.", # description
                                                             "icon": "images/achi/gp.png" # 96x96 image
                                                             },          
                                        "Shopping_Time!": {"type": 0, # One time achievent
                                                             "title": "Shopping Time!", # Also neame for steam
                                                             "text": "You bought a new item for the clinic!", # description
                                                             "icon": "images/achi/gp.png" # 96x96 image
                                                             },  
                                        "ISWTT": {"type": 0, # One time achievent
                                                             "title": "In step with the times", # Also neame for steam
                                                             "text": "You made an app available to patients.", # description
                                                             "icon": "images/achi/gp.png" # 96x96 image
                                                             },     
                                        "Indebted": {"type": 0, # One time achievent
                                                             "title": "Indebted", # Also neame for steam
                                                             "text": "You took a loan.", # description
                                                             "icon": "images/achi/gp.png" # 96x96 image
                                                             },   
                                        "IADNAP": {"type": 0, # One time achievent
                                                             "title": "I'm a doctor, not a photographer!", # Also neame for steam
                                                             "text": "You took pictures for Dr. Kirkman.", # description
                                                             "icon": "images/achi/gp.png" # 96x96 image
                                                             },            
                                        "Turn_Around": {"type": 0, # One time achievent
                                                             "title": "Turn Around", # Also neame for steam
                                                             "text": "You had a massage.", # description
                                                             "icon": "images/achi/gp.png" # 96x96 image
                                                             },         
                                        "UmbHernia": {"type": 0, # One time achievent
                                                             "title": "Umbilical Hernia", # Also neame for steam
                                                             "text": "You completed Nolan's examination.", # description
                                                             "icon": "images/achi/gp.png" # 96x96 image
                                                             },                                                                  
                                        "KikoCompleted": {"type": 0, # One time achievent
                                                             "title": "Boarding schooler", # Also neame for steam
                                                             "text": "You completed Kiko's examination.", # description
                                                             "icon": "images/achi/gp.png" # 96x96 image
                                                             }, 
                                        "KikoBlackmail": {"type": 0, # One time achievent
                                                             "title": "Blackmailer", # Also neame for steam
                                                             "text": "You blackmailed someone.", # description
                                                             "icon": "images/achi/gp.png" # 96x96 image
                                                             },
                                        "TooYoung": {"type": 0, # One time achievent
                                                             "title": "Too Young!", # Also neame for steam
                                                             "text": "You completed Fanny's examination.", # description
                                                             "icon": "images/achi/gp.png" # 96x96 image
                                                             },                                                                       
                                        "Harassed": {"type": 0, # One time achievent
                                                             "title": "I fell from the stairs!", # Also neame for steam
                                                             "text": "You completed Bridget's examination.", # description
                                                             "icon": "images/achi/gp.png" # 96x96 image
                                                             },     
                                        "*Famous*": {"type": 1, # Progress achievent
                                                             "title": "Famous",
                                                             "text": "Your clinics reached 50 fame!",
                                                             "icon": "images/steth.png",
                                                             "cur_prog": 0, # current progress 
                                                             "max_prog": 50 # maximal progress
                                                             }
                                        }
                                        

        for i, a in persistent.achievements_dict.items():
            if a['type'] == 0:
                achievement.register(i, steam=a['title'])
            if a['type'] == 1:
                achievement.register(i, steam=a['title'], stat_max=a['max_prog'])

User avatar
Bruni Multimedia
Regular
Posts: 114
Joined: Mon May 15, 2017 12:23 pm
Projects: Yomi Alliance
Organization: Bruni Multimedia
itch: brunimultimedia
Contact:

Re: Strange problem with achievements

#3 Post by Bruni Multimedia »

Any idea anyone?

User avatar
Bruni Multimedia
Regular
Posts: 114
Joined: Mon May 15, 2017 12:23 pm
Projects: Yomi Alliance
Organization: Bruni Multimedia
itch: brunimultimedia
Contact:

Re: Strange problem with achievements

#4 Post by Bruni Multimedia »

No one uses achievements? :o

User avatar
PyTom
Ren'Py Creator
Posts: 16093
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Strange problem with achievements

#5 Post by PyTom »

This looks like a bug that's entirely in your code, so it's not clear what support you expect.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
Bruni Multimedia
Regular
Posts: 114
Joined: Mon May 15, 2017 12:23 pm
Projects: Yomi Alliance
Organization: Bruni Multimedia
itch: brunimultimedia
Contact:

Re: Strange problem with achievements

#6 Post by Bruni Multimedia »

Hey PyTom, thanks for answering, I'm a great fan of yours!

I think the code I posted is correct, still the game crashes. I just call the achievements I make and they make the game crash. So I was wondering if you see something wrong in the code I posted, since I can't find anything.

Besides, this happens only with updated versions of the game, not with the first install, and only compiled versions. Deleting persistent just works for the development environment... :(

User avatar
Divona
Miko-Class Veteran
Posts: 678
Joined: Sun Jun 05, 2016 8:29 pm
Completed: The Falconers: Moonlight
Organization: Bionic Penguin
itch: bionicpenguin
Contact:

Re: Strange problem with achievements

#7 Post by Divona »

What strike me as odd is this part of the traceback:

Code: Select all

  File "game/kiko_1.rpy", line 903, in <module>
    $ get_achievement("Kiko_Completed", trans=achievement_transform)
  File "game/achievement.rpy", line 66, in get_achievement
    ach = persistent.achievements_dict[ach_id]
KeyError: u'KikoCompleted'
First we have:

Code: Select all

    $ get_achievement("Kiko_Completed", trans=achievement_transform)
But KeyError give out:

Code: Select all

    KeyError: u'KikoCompleted'
There is no "Kiko_Completed" in "persistent.achievements_dict". Could this be the issue?
Completed:
Image

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Strange problem with achievements

#8 Post by Imperf3kt »

Hmm, the above combined with the fact it works for the developer but not other players leads me to believe the issue is probably related to define vs default.

How do you define your achievements variables? You should be using 'default'

Make any necessary changes, delete persistent data, force a recompile and then see if the error persists.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
Bruni Multimedia
Regular
Posts: 114
Joined: Mon May 15, 2017 12:23 pm
Projects: Yomi Alliance
Organization: Bruni Multimedia
itch: brunimultimedia
Contact:

Re: Strange problem with achievements

#9 Post by Bruni Multimedia »

Imperf3kt wrote: Sun Oct 29, 2017 11:31 pm Hmm, the above combined with the fact it works for the developer but not other players leads me to believe the issue is probably related to define vs default.

How do you define your achievements variables? You should be using 'default'

Make any necessary changes, delete persistent data, force a recompile and then see if the error persists.
What do you mean "how do I define"? There's no definition at all, I simply call for the achievement when needed. How should I define them?

@Divona: I checked that too. It only changed the traceback. The copypaste was made before the correction, so that's why it's different.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Strange problem with achievements

#10 Post by Imperf3kt »

You need to define the achievement before granting it.

default persistent.achievements_Kiko_Completed = False
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
Bruni Multimedia
Regular
Posts: 114
Joined: Mon May 15, 2017 12:23 pm
Projects: Yomi Alliance
Organization: Bruni Multimedia
itch: brunimultimedia
Contact:

Re: Strange problem with achievements

#11 Post by Bruni Multimedia »

Imperf3kt wrote: Wed Nov 01, 2017 4:24 pm You need to define the achievement before granting it.

default persistent.achievements_Kiko_Completed = False
Thank you VERY MUCH. That helped a lot!

Post Reply

Who is online

Users browsing this forum: Google [Bot]