How to set up persistent data within a RevertableSet

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
User avatar
thirstyoctopus
Regular
Posts: 72
Joined: Mon Aug 27, 2018 12:04 pm
Projects: Romance Visual Novel story
Organization: Thirsty Octopus
Contact:

How to set up persistent data within a RevertableSet

#1 Post by thirstyoctopus » Sat Mar 19, 2022 2:55 pm

Hi guys

I've been struggling for a while trying to figure out the best way to do this thing but now I'm stuck and need some advice.

My game includes three characters, each has their own good ending (and bad ending). I need to set up a persistent variable for when an ending is achieved so it knows who's route they've successfully completed.

Currently I'm using the RevertableSet persistent method which I think suits best. I set my persistent up as follows (the names in the object being the names of the characters whose ending you can achieve):

Code: Select all

if persistent.seen_ending is None:
        persistent.seen_ending = set({'lily','rose','iris'})
Then I register the persistent with the following function:

Code: Select all

def merge_endings(old, new, current):
        current.update(old)
        current.update(new)
        return current

renpy.register_persistent('seen_ending', merge_endings)
When I want to set it, I use:

Code: Select all

$ persistent.seen_ending.lily = True
But if I do a check on any of the others to see if they are True, I get an error saying that it doesn't exist. Basically I need to know how I'm able to do a check on the other endings, something along the lines of 'does this variable exist in the current set' but, in code obviously. Because if I simply put:

Code: Select all

if persistent.seen_endings.rose:
     // do something here
Then it just tells me that 'rose' does not exist in the RevertableSet() 'seen_endings' even though I have set that right at the beginning - unless I'm missing something? Any help on this is much appreciated.

Thanks
Michael

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

Re: How to set up persistent data within a RevertableSet

#2 Post by Ocelot » Sat Mar 19, 2022 3:39 pm

That not how sets work.

If you want to use sets, you can do something like:

Code: Select all

default persistent.seen_ending = set() # Be default you didn't see any endings yet

# On ending:
$ persistent.seen_ending.add('rose')

# if you want to test if player encountered ending
if 'lily' in persistent.seen_ending:
    # . . .
< < insert Rick Cook quote here > >

User avatar
thirstyoctopus
Regular
Posts: 72
Joined: Mon Aug 27, 2018 12:04 pm
Projects: Romance Visual Novel story
Organization: Thirsty Octopus
Contact:

Re: How to set up persistent data within a RevertableSet

#3 Post by thirstyoctopus » Sun Mar 20, 2022 9:12 am

Ocelot wrote:
Sat Mar 19, 2022 3:39 pm
That not how sets work.

If you want to use sets, you can do something like:

Code: Select all

default persistent.seen_ending = set() # Be default you didn't see any endings yet

# On ending:
$ persistent.seen_ending.add('rose')

# if you want to test if player encountered ending
if 'lily' in persistent.seen_ending:
    # . . .
Ah so that's how they work. Thanks - I just wasn't quite sure how to push values into them.

Post Reply

Who is online

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