Remembering choices through all saves?

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
quinnsea
Regular
Posts: 59
Joined: Wed Apr 26, 2017 5:04 pm
Completed: Birch Sapling
Projects: Aspen, Baleen
Organization: Koimarina Games
IRC Nick: quinnsea
Tumblr: bonnievoyage
Soundcloud: nishiikigoi
itch: koimarina
Location: Missouri
Contact:

Remembering choices through all saves?

#1 Post by quinnsea »

Hey, I'm super new to futzing around with Ren'Py. There's a route in my game I want to only make available when someone has gone through the game at least once.

What's the code for that and where should I put it? Thank you!

User avatar
DannyGMaster
Regular
Posts: 113
Joined: Fri Sep 02, 2016 11:07 am
Contact:

Re: Remembering choices through all saves?

#2 Post by DannyGMaster »

You can use a variable to check how many times the player has cleared the game, you could make it persistent so the game will remember it throughout all saves. Here's a short example:

Code: Select all

#Define a new variable called persistent.cleared_times, you increase it each time the game ends.
define persistent.cleared_times = 0

label start:

    "Welcome to the shortest game ever."
 
    #Checks if the game has been completed, put it here first so it's easier to check.
    if persistent.cleared_times > 0:

        "Hello again, friend, thanks for playing the game again."

        "With this you have cleared it a total of [persistent.cleared_times] times."

        "For such a nice customer, I've unlocked an extra route, just for you."

        menu:
            "Do you want to go through it?"

            "Yeah!":

                "Very well, going there now."

                jump extra #This is the extra route label

            "Nope":

                "Okay, see you next time then."

                jump first_choice

label first_choice:

    menu:
        "Will you replay the game?"

        "Yes!":

            "Very well see you on New Game Plus"

            "Good ending."

            $ persistent.cleared_times += 1 #After the game ends, you update the variable.

            return

        "No...":

            "Oh okay your loss."

            "Bad end"
            
            #I chose not to update the variable here since this is a bad ending.

            return

label extra:

    "This is the extra route."

    "Sadly it's not much, but anyway thanks, you're an awesome person!"

    #Update the variable here too, since this is a good ending
    $ persistent.cleared_times += 1

    "Best ending."

    return
This is merely an example for demonstration purposes, you can update the variable or check it anytime you want.
The silent voice within one's heart whispers the most profound wisdom.

User avatar
quinnsea
Regular
Posts: 59
Joined: Wed Apr 26, 2017 5:04 pm
Completed: Birch Sapling
Projects: Aspen, Baleen
Organization: Koimarina Games
IRC Nick: quinnsea
Tumblr: bonnievoyage
Soundcloud: nishiikigoi
itch: koimarina
Location: Missouri
Contact:

Re: Remembering choices through all saves?

#3 Post by quinnsea »

Oh, okay! So would it be something like...

Code: Select all

define persistent.cleared_times = 0

label start:
    "...!"
    if persistent.cleared_times > 0:
    jump route_option

    if persistent.cleared_times = 0:
    jump unplayed

label unplayed:
    "This is the normal story! If you want to try a different story, pick an option!"

    menu:
            "Okay.":

            "Alright! We'll get you right to it!"
            $ persistent.cleared_times += 1

            return

            "Thanks!":

            "You're welcome! Let's go!"
            $ persistent.cleared_times += 1

            return

label route_option:

    "Whoa, thanks for playing again!"
    "Since you're playing so much, I'll give you a different option this time!"

     menu:

          "Really?":

          "Yep! Oh, I forgot one thing."
          "This choice is meaningless! Whoopsie! Try again!"

          jump unplayed

          "Cool!":

          "I know, right?"
          "Let's get to the real bulk of the story!"

          jump undetermined
          
I obviously didn't put any label as undetermined, but otherwise this is how it should look?
ImageImage

quinn / 26 / qa analyst, game design hobbyist
icon by church

User avatar
DannyGMaster
Regular
Posts: 113
Joined: Fri Sep 02, 2016 11:07 am
Contact:

Re: Remembering choices through all saves?

#4 Post by DannyGMaster »

Yes, that is one way to do it, but there are many possibilities depending on what you want to achieve, you can always add any number of persistent variables you like and make your game react to them in any way you want, just make sure they're named 'persistent.something' so the game knows they should be remembered. You don't need to have the player choose if they want to see the extra or not, you could make the game jump directly if the conditions are met, but I think it is good to let them know somehow where they're getting at. It's up to you, really.

One thing to look out for is the if statements, and identation, the code as you wrote it probably would give you a bunch of errors. Like here:

Code: Select all

if persistent.cleared_times = 0:
    jump unplayed        
It should be:

Code: Select all

if persistent.cleared_times == 0:
    jump unplayed 
Equality comparisons are written with '==' because '=' is used for assignment. And the code that will run if the condition is met should be indented. Aside from that, it looks good!
The silent voice within one's heart whispers the most profound wisdom.

Post Reply

Who is online

Users browsing this forum: No registered users