how do you use persistent data? (solved)

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
BreathingColors
Newbie
Posts: 8
Joined: Sun Jul 16, 2017 2:30 pm
Tumblr: BreathungColorsDraws
Deviantart: JewelBreathingColors
Contact:

how do you use persistent data? (solved)

#1 Post by BreathingColors »

Code: Select all

label start:
    
    $ persistent.gasterend = 0
    $ persistent.Freshend = None
    $ persistent.killerend = None
    
    if persistent.gasterend == True:
        menu:
            "Reset":
                $ persistent.Freshend = False
                $ persistent.killerend = False
                return
            "return":
                return
    else:
        jump start_2
        
    
label start_2:
    scene bg room
    show GF 1

    GF"Hello, world."
    show GF 2
    GF"You've created a new Ren'Py game."
    GF"Once you add a story, pictures, and music, you can release it to the world!"
    
    if persistent.freshend == True and persistent.killerend == True:
        jump c
    else:
        jump b
label b:
    menu:
        "fresh end":
            $ persistent.freshend = True
            $ renpy.save_persistent()
            jump freshending
        "killer end":
            $ persistent.killerend = True
            $ renpy.save_persistent()
            jump freshending
label c:
    menu:
        "gaster end":
            $ persistent.gasterend += 1
            $ renpy.save_persistent()
            if persistent.gasterend == 1:
                jump gasterending
            if persistent.gasterend > 1
                jump gasterending2
        "fresh end":
            $ persistent.freshend = True
            jump freshending
        "killer end":
            $ persistent.killerend = True
            jump freshending
            
label gasterending:
    "gaster end"
    return
label gasterending2:
    "gaster end2"
    return
label freshending:
    "fresh/killer end"
    return 
So what I'm trying to do is once you get all the endings you have the option to choose gasters end, once you get gasters end you can do a restart except for gaster, gasters ending cannot be reset
Last edited by BreathingColors on Wed Jan 09, 2019 5:08 pm, edited 2 times in total.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: how do you use persistent data?

#2 Post by Imperf3kt »

I recommend against it being a once view only route, no reset, but anyway:

Code: Select all

# Define all variables before the start label with default

default persistent.gasterend = 0
default persistent.Freshend = None
default persistent.killerend = None

label start:
The rest of your code is too difficult to read on a mobile device.

Also, use code not c when pasting your code.
c is for one liners
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: how do you use persistent data?

#3 Post by trooper6 »

Please note, while regular variables are divines using default, persistent variables are declared using define.

So:

Code: Select all

# Define all variables before the start label with default

define persistent.gasterend = 0
define persistent.Freshend = None
define persistent.killerend = None

label start:
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: how do you use persistent data?

#4 Post by Imperf3kt »

Woops, did I write default? Guess I did.
Another case of just-woke-up -I-shouldn't-be-on-the-computer.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

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: how do you use persistent data?

#5 Post by PyTom »

Persistents work the same way with default and define, so both are correct. I think "default" is probably the better one to use, since it's semantically closer to what's happening.
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

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: how do you use persistent data?

#6 Post by trooper6 »

Thanks for the info PyTom, the Changelog seemed to imply that persistent variables should use define...knowing that I can use default for everything makes my life easier. The difference between default and define isn't very clearly articulated in the documentation.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

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: how do you use persistent data?

#7 Post by PyTom »

It's possible it's an older changelog. Define came first, and default second.

Generally, nowadays, if something can change, use default. If something can't (a character or constant), use define. In fact, changing something that's been defined can lead to problems, as Ren'Py is willing to optimize variables set using define.
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

Post Reply

Who is online

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