Problem with Persistent Variables

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
BM90
Newbie
Posts: 15
Joined: Sat Mar 31, 2018 2:48 am
Contact:

Problem with Persistent Variables

#1 Post by BM90 » Sat Mar 31, 2018 4:17 am

Hello,

I need some assistance getting my persistent variables set correctly. I apologize up front if I'm missing something obvious. I'm still quite new to Ren'Py.

What I'm attempting to do is add images to the main screen if the player has progressed past certain points in the story. In my script I have lines such as this:

Code: Select all

$ persistent.checkpoint_1 = True
$ renpy.save_persistent()
I'm using the second line to immediately save the persistent data after the flag is reached, that way the main menu should update even if the player doesn't fully exit the game. Under the main_menu screen I added this:

Code: Select all

if persistent.checkpoint_1:
        add "image_1.png"
This is working. Sort of... Now every time the game is started, the image will show up on the main menu regardless of the progression in the story. I've deleted the persistent save, but even without it the image still shows up. After thinking about it for a while, the only thing I could figure was that it wasn't properly reading the value for some reason. To confirm I displayed the value in game and it comes up as 1 automatically, which I believe is how it's displaying True in this case. I'm not sure why that is. I've tried to force the value to False by various means, but with no success. Can anyone offer any advice on how to get this to work?

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

Re: Problem with Persistent Variables

#2 Post by Ocelot » Sat Mar 31, 2018 7:30 am

Did you do "delete persistent" in launcher? Game can save persistent data in different non-obvious places. DId you try to set it to False manually (modify script, adding code to set it to False at start, edit code again and remove that code, or use console)?
< < insert Rick Cook quote here > >

BM90
Newbie
Posts: 15
Joined: Sat Mar 31, 2018 2:48 am
Contact:

Re: Problem with Persistent Variables

#3 Post by BM90 » Sat Mar 31, 2018 3:35 pm

Using "Delete Persistent" in the launcher did the trick. I was manually deleting the file, but from the "wrong" location. Never noticed the button before.

I guess that leads me to another questions though: Why are there two different locations where save data is stored? I have one in AppData and one in Documents. It looks like the actual save files are being pulled from Documents, but the persistent data can be pulled from either location. If I delete it in one of the folders, the game still reads it out of the other. Is this intentional? I don't believe I've messed with anything related to saving other than turning off autosave.

User avatar
Qlara
Regular
Posts: 80
Joined: Fri Nov 28, 2014 10:22 am
Completed: Carmilla
Skype: kantonija
itch: visualgothic
Location: Berlin
Contact:

Re: Problem with Persistent Variables

#4 Post by Qlara » Tue Apr 03, 2018 6:04 pm

Unfortunately, I can't help you, but I have a related problem that you seem to have figured out.
I'd like to deactivate the Load button until the user has actually saved the game, like I did for the Notes button, but I don't know how and where to set the flag. (And I'm also very confused about save file locations.)

Code: Select all

textbutton _("Load") action ShowMenu("load")
textbutton _("Notes") action If(persistent.unlock_notes, Show("notes"))

BM90
Newbie
Posts: 15
Joined: Sat Mar 31, 2018 2:48 am
Contact:

Re: Problem with Persistent Variables

#5 Post by BM90 » Wed Apr 04, 2018 9:56 pm

I'm not an expert, but maybe you could add an additional action to the save button that sets a persistent variable. That sort of achieves your goal, although the load button will stick around even if the player deletes all of the saves. I don't think I've come across anything that can check whether a save file exists. If such a thing did exist, that'd be what you'd want to use in your if statement.

User avatar
Qlara
Regular
Posts: 80
Joined: Fri Nov 28, 2014 10:22 am
Completed: Carmilla
Skype: kantonija
itch: visualgothic
Location: Berlin
Contact:

Re: Problem with Persistent Variables

#6 Post by Qlara » Wed Apr 11, 2018 6:18 am

The save button takes you to the save screen and doesn't actually save.
The problem is that the user can save in any slot, so I can't add the additional action there either.
I'm pretty sure there must be a simple solution with a function that checks whether a file exists.

User avatar
Qlara
Regular
Posts: 80
Joined: Fri Nov 28, 2014 10:22 am
Completed: Carmilla
Skype: kantonija
itch: visualgothic
Location: Berlin
Contact:

Re: Problem with Persistent Variables

#7 Post by Qlara » Wed Apr 11, 2018 8:39 am

My problem is now also solved:

Code: Select all

        default lastsave = renpy.newest_slot(r"\d+")
        if lastsave != None:
            textbutton _("Load") action ShowMenu("load")

Post Reply

Who is online

Users browsing this forum: _ticlock_