Persistent Data

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
wyverngem
Miko-Class Veteran
Posts: 615
Joined: Mon Oct 03, 2011 7:27 pm
Completed: Simple as Snow, Lady Luck's Due,
Projects: Aether Skies, Of the Waterfall
Tumblr: casting-dreams
itch: castingdreams
Location: USA
Contact:

Persistent Data

#1 Post by wyverngem »

I'm having trouble with a bit of persistent data. I have a persistent variable that I'm using to control if on the splashscreen the reader will begin a new game or be brought to the menu. I also use it to see if the reader has seen the whole prologue. I start the game and it automatically jumps to the "start" label. Then I read through the story and am sent to the main menu. From the main menu I start a new game it remembers that I've already seen the prologue and gives me the option to skip what I've read. I than close the program and start fresh.

I have a line that shows me what my "persistent.op_unlocked" is set to before I start the if statement. When I close the game and start fresh it says that the variable is set to "False" even though I set it to "True" after the prologue. Any ideas on what could be causing the issue? Could it be that I've set the variable up original in a "init -2"?

Code: Select all

init -2:
    $ persistent.op_unlocked = False
    
# The game starts here.
label splashscreen:
    #Title screen.
    $ renpy.pause(0)
    scene black
    "Title Here"
    #Go to start if it's their first time playing and seeing the full opening.
    "[persistent.op_unlocked]"
    if persistent.op_unlocked == False:
        jump start
    return
    
label start:
    scene black with fade
    "Prestory here."
    # Makes a skip option so those who've seen the whole opening can skip it.
    if persistent.op_unlocked == True:
        show text "You seen the opening, Choose to skip the prologue." at hc
        menu:
            "Skip":
                call Prologue
            "Don't skip":
                pass
    else:
        call Prologue
    #Persistent set to True here so if the opening is not fully scene they don't have the skip option.
    #When game is opened again spalshscreen will go to the main menu and not jump to start.
    $ persistent.op_unlocked = True
    jump Chapter1
    
# The story continues...

Valmoer
Regular
Posts: 53
Joined: Sat Feb 04, 2012 9:46 pm
Contact:

Re: Persistent Data

#2 Post by Valmoer »

wyverngem wrote:Any ideas on what could be causing the issue? Could it be that I've set the variable up original in a "init -2"?
Indeed, what is happening here is that you reset your persistent variable every time you launch the application.
Quoting the documentation,
Documentation wrote:The persistent object is special in that an access to an undefined field will have a None value, rather than causing an exception.
Therefore, if you want to know if the variable has been initialized, you can drop the init and substitute

Code: Select all

   if persistent.op_unlocked == False:
        jump start
    return
with

Code: Select all

   if persistent.op_unlocked is None
        jump start
    return
Hope it helps!

Reference : http://www.renpy.org/doc/html/persistent.html

User avatar
wyverngem
Miko-Class Veteran
Posts: 615
Joined: Mon Oct 03, 2011 7:27 pm
Completed: Simple as Snow, Lady Luck's Due,
Projects: Aether Skies, Of the Waterfall
Tumblr: casting-dreams
itch: castingdreams
Location: USA
Contact:

Re: Persistent Data [solved]

#3 Post by wyverngem »

Thanks, working fine now.

Post Reply

Who is online

Users browsing this forum: Yone28