[solved] Persistent dictionary disappearing upon restart :(

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.
Message
Author
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: Persistent dictionary disappearing upon restart :(

#16 Post by PyTom »

You are not allowed to have side effects in screens. If you have side effects in screens, you'll have this problem.
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

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Persistent dictionary disappearing upon restart :(

#17 Post by kivik »

Yeah looks like screen predict is going to mess this up big time, I think you need to wrap this around a function or a label to add your pic to the list instead of doing it within the screen. It's the problem of mixing logic with screens unfortunately!

You should be able to do a find in folder and replace, change all call screen show_pic to your function call or label.

You also want to add a condition statement if you want to stop the same pic being appended constantly:

Code: Select all

if pic not in persistent.seen_list:
    persistent.seen_list.append(pic)

philat
Eileen-Class Veteran
Posts: 1909
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Persistent dictionary disappearing upon restart :(

#18 Post by philat »

Your tester doesn't show that any problem with persistent getting reset, just the fact that you shouldn't use python that way inside screens.

As for the latter question, are you actually calling the screen manually? You said this is some sort of gallery-related thing, so that seemed unlikely. The point of asking for a recreation was to see how you're fitting everything together. But anyway. If you're actually just calling the screen from renpy script, you can just use an on "show" action.

Code: Select all

screen show_pic(pic, x = None, y = None, proportional = True, bg = "#000"):
    on "show" action AddToSet(persistent.seen_list, pic)
    # everything else

goldo
Regular
Posts: 127
Joined: Mon Jan 23, 2017 8:23 am
Contact:

Re: Persistent dictionary disappearing upon restart :(

#19 Post by goldo »

philat wrote: Fri Jun 01, 2018 9:40 pm Your tester doesn't show that any problem with persistent getting reset, just the fact that you shouldn't use python that way inside screens.

As for the latter question, are you actually calling the screen manually? You said this is some sort of gallery-related thing, so that seemed unlikely. The point of asking for a recreation was to see how you're fitting everything together. But anyway. If you're actually just calling the screen from renpy script, you can just use an on "show" action.

Code: Select all

screen show_pic(pic, x = None, y = None, proportional = True, bg = "#000"):
    on "show" action AddToSet(persistent.seen_list, pic)
    # everything else
Brilliant, I didn't know the 'on "show"' statement, it is exactly what I was looking for! Thank you! :D

It works just fine with the test game.

Unfortunately, when I try to use it within the actual game, it throws an error when returning to the main menu: :?

Edit: The error was because some objects were mistakenly included in the list. Now it works, but the persistent list is still being killed when restarting. I have to keep looking :(


Edit 2:

Image

Amazing! I finally got it to work!!!

The problem was coming from one of the screen I work with, which was getting an im.Scale input as a picture. I think storing that kind of object threw it off.

Anyway, I disabled that part of the code, and the rest works, which is what I needed for the CG gallery anyway.

Thanks to everyone who pitched in!!! :D
Last edited by goldo on Sat Jun 02, 2018 6:27 am, edited 1 time in total.

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

Re: Persistent dictionary disappearing upon restart :(

#20 Post by Ocelot »

Can you post a minimal example which still exhibits your problem?
https://stackoverflow.com/help/mcve
http://sscce.org/

Do you have something, anything accessing that dictionary aside from your Show screen? Maybe a debug screen with purpose of clearing persistent data? Maybe ability for player to start from scratch? Maybe you unconditionally add stuff which should always be unlocked to dictionary in your script?

Can you save and do saves persist after restart? Maybe there are permission problems preventing data to be written on disc.
< < insert Rick Cook quote here > >

goldo
Regular
Posts: 127
Joined: Mon Jan 23, 2017 8:23 am
Contact:

Re: Persistent dictionary disappearing upon restart :(

#21 Post by goldo »

Thanks Ocelot, actually it works now! I'll see if I can still reproduce that problem on a test game, for science

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Persistent dictionary disappearing upon restart :(

#22 Post by kivik »

Just to chip in again - have you checked to make sure you're not constantly adding to the persistent list with dups? My understanding is that AddToSet() won't check for duplicates so your persistent list will just keep growing and growing every time your player replays the game. Maybe a Function() action that triggers your own function, which checks for dups first would be worth implementing?

goldo
Regular
Posts: 127
Joined: Mon Jan 23, 2017 8:23 am
Contact:

Re: [solved] Persistent dictionary disappearing upon restart :(

#23 Post by goldo »

So, here is the whole story.

Some of the pictures were accessed through a very simple screen like this:

Code: Select all

screen show_img(img):
    on "show" action Function(unlock_pic, img) # This is how the game tracks that this particular picture has been seen.
        
    add img
Most of the time, this screen would receive the name of a renpy image as the img argument, but every once in a while, it would get passed a ProportionalScale object, such as:

Code: Select all

show screen show_img(ProportionalScale("items/apples.png", 500, 500))
Now, even though it would work exactly as a renpy image within the screen, it's still not a native renpy object.

I think that's why it doesn't save as a persistent variable. I have tested this independently, and any list or dict containing a ProportionalScale object is getting scrapped upon restart, although strangely no error message is shown.

So that's the long and short of it.

Thanks everyone for your help! :D

Post Reply

Who is online

Users browsing this forum: No registered users