[SOLVED] Gallery - Persistent data not saved

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
Bren
Newbie
Posts: 18
Joined: Mon Aug 24, 2020 5:34 am
Contact:

[SOLVED] Gallery - Persistent data not saved

#1 Post by Bren »

Hi guys,

Update: I had included the function "persistent._clear(progress=True)" somewhere else in my script long time ago and I completely forgot about it, so obviously all persistent data would be cleared every time I restart the game. I removed it and it works just fine!

*************

I have been stuck for a while on what is probably a simple issue, but I really can't figure out what exactly!

I have used Ren'py documentation to build a very simple gallery with locked CGs - they get unlocked as the story goes through persistent variables. It works just fine as I keep playing, but for some reason, I cannot get to make these persistent data saved once I restart / reload the game!

Gallery code is the following:

Code: Select all

init python:

    g = Gallery()

    g.locked_button = "gallery_locked_button.png"
    
    g.button("slot01")
    g.condition("persistent.cg1_unlocked")
    g.image("cg1.png")

    g.button("slot02")
    g.condition("persistent.cg2_unlocked")
    g.image("cg2.png")

    g.transition = dissolve


screen gallery:

    tag menu

    grid 2 2:

        xfill True
        yfill True

        add g.make_button("slot01", "CG/CG6_raph_vs_seb.png", xalign=0.5, yalign=0.5)
        add g.make_button("slot02", "CG/CG5_raph_alice_tower.png", xalign=0.5, yalign=0.5)

        textbutton "Return" action Return() xalign 0.5 yalign 0.5
        textbutton "Main menu" action MainMenu() xalign 0.5 yalign 0.5

And inside the script.rpy I put the following:

Code: Select all

a 'You will unlock new CGs!'

$ persistent.cg1_unlocked = True
$ persistent.cg2_unlocked = True
$ renpy.save_persistent()

Once I restart the game, it seems that both persistent data go back to Null as the CGs get locked again. Would anyone have an idea on how I can make sure the persistent data are saved?

Many thanks!
Last edited by Bren on Thu Jul 08, 2021 7:28 am, edited 4 times in total.

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

Re: Gallery - Persistent data not saved

#2 Post by Ocelot »

Is this all code? Does anything, anywhere else reference cg1_unlocked ?
< < insert Rick Cook quote here > >

Bren
Newbie
Posts: 18
Joined: Mon Aug 24, 2020 5:34 am
Contact:

Re: Gallery - Persistent data not saved

#3 Post by Bren »

Hi Ocelot, thanks for your help!

Yes I'm afraid so - I've even tried changing the names only in these specific parts to make sure there would be not impact from any other forgotten reference, but no luck either.

Do I need to declare these persistent data first somewhere? Or add a special authorization somewhere in Renpy's code to be allowed to register my own persistent data?

Bren
Newbie
Posts: 18
Joined: Mon Aug 24, 2020 5:34 am
Contact:

Re: Gallery - Persistent data not saved

#4 Post by Bren »

Quick update: it seems that actually no persistent data can be saved on this specific project - I tried it over by creating a whole new project and it worked just fine.

The project I'm working on has been c/c directly from another project's folder in the renpy-7.3.5-sdk folder - I have then updated the options.rpy file to change the name of the project and modify the config.save_directory variable accordingly. Could the issue come from this? Is there another step I need to do?
FYI the new save_directory has been properly created and I can see in the relating folder (%APPDATA\RenPy\<config.save_directory>) all saved files and persistent file necessary for the game to launch.

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

Re: Gallery - Persistent data not saved

#5 Post by rayminator »

I have read that you used the one from the renpy documents Image Gallery
but it looks like that you are missing something... something like this...

Code: Select all

 # The final two buttons contain images that show multiple pictures
    # at the same time. This can be used to compose character art onto
    # a background.
    g.button("dawn mary")
    g.unlock_image("dawn1", "mary dawn wistful")
    g.unlock_image("dawn1", "mary dawn smiling")
    g.unlock_image("dawn1", "mary dawn vhappy")

    g.button("dark mary")
    g.unlock_image("beach2", "mary dark wistful")
    g.unlock_image("beach2", "mary dark smiling")
    g.unlock_image("beach2", "mary dark vhappy")

Bren
Newbie
Posts: 18
Joined: Mon Aug 24, 2020 5:34 am
Contact:

Re: Gallery - Persistent data not saved

#6 Post by Bren »

Found the issue! It was such a rookie mistake from me, I'm super ashamed => long time ago I had created a stupid file including persistent._clear(progress=True). I thought this was called only when I activated a specific function, but turns out it was actually active every single time I would restart the game. Just removed this persistent._clear(progress=True) and it works perfectly fine!

Very sorry for the stupid question (issue was actually unrelated to the code displayed in this topic), and many thanks for all your help!

Post Reply

Who is online

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