OlegWock / Roselia-achievements

RenPy achievements module
MIT License
76 stars 10 forks source link

When using achievement.get_progress(name) it crashes on reload #5

Open raspberry-soft opened 2 years ago

raspberry-soft commented 2 years ago

It's because the achievements needs to be registered at init time but they are indented under if not persistent.achievements_dict: so when reloading the game they are not registered.

The solution is to outdent it like this:

    # Define your achievements here
    if not persistent.achievements_dict:
        persistent.achievements_dict = {"*achievent_name*": {"type": 0, # One time achievent
                                                             "title": "Котик!", # Also neame for steam
                                                             "text": "А где же блины?", # description
                                                             "icon": "images/icons/ach1.png" # 96x96 image
                                                             },
                                        "*achievent_name*": {"type": 1, # Progress achievent
                                                             "title": "",
                                                             "text": "",
                                                             "icon": "images/icons/ach.png",
                                                             "cur_prog": , # current progress 
                                                             "max_prog": # maximal progress
                                                             }
                                        }

    for i, a in persistent.achievements_dict.items():  ###### Outdent this block.
        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'])