Page 1 of 1

[SOLVED] Crashes after resetting game - Persistent data/ Achievements

Posted: Tue Jun 19, 2018 5:00 am
by Kinmoku
Hi all. I had issues a while back with an achievement ("true detective") where it's achieved when every item in the game has been clicked on. It cannot be done in one playthrough, so the data is persistent. My original post is here: viewtopic.php?f=8&t=45439&p=463461#p463461

This worked fine until the game is reset. If it's reset, and you click on an item, the game crashes. Sadly, I have only just discovered this terrible bug but I want to fix it.

Here's my code in script.rpy:

Code: Select all

init -2:
    default persistent.itemcount = set()
Achievement registers after an exploration scene (this causes crashes too):

Code: Select all

    if len(persistent.itemcount) == 31:
        $achievement.grant("detective")
        init:
            $achievement.register("detective")
My reset button jumps to:

Code: Select all

label resetprogress:
     $ persistent._clear(progress=True)
     $ persistent.endings = []
     call screen main_menu
I assume that I need "persistent.itemcount = 0" or something, but whatever I try seems to cause more crashes. Any ideas?

Re: Crashes after resetting game - Persistent data/ Achievements

Posted: Tue Jun 19, 2018 5:31 am
by gas
I dunno why you did an init before assignin the achievement.register...or anything else. Achievement. is a function that play ar regular runtime.

Re: Crashes after resetting game - Persistent data/ Achievements

Posted: Wed Jun 20, 2018 3:30 am
by Kinmoku
gas wrote: Tue Jun 19, 2018 5:31 am I dunno why you did an init before assignin the achievement.register...or anything else. Achievement. is a function that play ar regular runtime.
'cause I didn't know any better, haha! Anyway, I changed it and it still doesn't work. In fact, it resets the game every time I load.

An error is still being thrown up when I manually reset the game and click on an item too :(

Re: Crashes after resetting game - Persistent data/ Achievements

Posted: Wed Jun 20, 2018 5:04 am
by kivik
What's the error?

Re: Crashes after resetting game - Persistent data/ Achievements

Posted: Wed Jun 20, 2018 5:47 am
by Kinmoku
kivik wrote: Wed Jun 20, 2018 5:04 am What's the error?
Sorry, it's the same one I had originally, but this time it comes back after reset only. download/file.php?id=44763&mode=view

When I remove the "init -2:" the error is 'RevertableList' object has no attribute 'add'. I attached the full report.

Re: Crashes after resetting game - Persistent data/ Achievements

Posted: Thu Jun 21, 2018 4:37 am
by Kinmoku
Okay, I've figured it out! In case anyone is interested, here are the changes I made:

Code: Select all

    default persistent.itemcount = set()
- removed the init

Code: Select all

label resetprogress:
     $ persistent._clear(progress=True)
     $ persistent.endings = []
     $ persistent.itemcount = set()
     call screen main_menu
- reset progress adds $ persistent.itemcount = set()

I've tested it a few times and it seems to have worked and reset properly :) Fingers crossed nothing else is lurking haha.

Re: [SOLVED] Crashes after resetting game - Persistent data/ Achievements

Posted: Thu Jun 21, 2018 7:01 am
by kivik
Hey sorry I started a reply yesterday but got interrupted and lost the post!

I was gonna say you probably want to remove your default persistent.itemcount = set() statement:

If anyone starts a new game, that line gets run - which wipes the itemcount variable. You'll probably want to create a label or function and call it at the beginning of a new game:

Code: Select all

label init_progress:
    if not persistent.itemcount:
        persistent.itemcount = set()

label start:
    call init_progress
I haven't tested it and I'm still a bit unfamiliar with python, but you want to check whether the itemcount exists or not first, and create it if not. Then it stays persistent across different games but doesn't crash on first run of the game.

You may want to mix the resetprogress label into it, by calling resetprogress if persistent.itemcount hasn't been set instead though.