Page 1 of 1

How to set up persistent data within a RevertableSet

Posted: Sat Mar 19, 2022 2:55 pm
by thirstyoctopus
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

Re: How to set up persistent data within a RevertableSet

Posted: Sat Mar 19, 2022 3:39 pm
by Ocelot
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:
    # . . .

Re: How to set up persistent data within a RevertableSet

Posted: Sun Mar 20, 2022 9:12 am
by thirstyoctopus
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.