[Solved] Finish 2 route to unlock secret route

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
bloodyhair
Regular
Posts: 61
Joined: Tue Aug 11, 2015 7:20 am
Deviantart: Takada-Wang
Contact:

[Solved] Finish 2 route to unlock secret route

#1 Post by bloodyhair »

I want to ask something. I want to make a game where the player need to unlock 2 of main bachelor route first before they can unlock the secret character route.

I found a code like this.

Code: Select all

if character.hasbeenintroduced == True:
    use code_that_you_wanted
I wonder if I can remade it into like this, and will this work or not?

Code: Select all

 if route characterA and characterB == goodEnding == True:
    
    "Congratulation! Route Character C is unlocked!"
    route character C == True
And, where did I need to put this code to? script.rpy? Or option.rpy? or screens.rpy?

Thank you so much for helping me *bow*
Last edited by bloodyhair on Thu Sep 03, 2015 7:13 am, edited 1 time in total.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
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: [Coding help] Finish 2 route to unlock secret route

#2 Post by PyTom »

I don't think that code will work. You probably want to use persistent for this.

The code needs to be distributed throughout the script. For each of the two main endings, you'll have code like:

Code: Select all

    $ persistent.unlocked_guy_1 = True
    "... and that's how I became a princess!"

Code: Select all

    $ persistent.unlocked_guy_2 = True
    "... and that's why I'm waking up with the cows each morning!"
And then you'll need to somehow make the third route conditional.

Code: Select all

    if persistent.unlocked_guy_1 and persistent.unlocked_guy_2:
        menu:
              "You know, I never wanted to do this. I wanted to be ... a Lumberjack! Swinging from tree to tree in the mighty forests of British Columbia.":
                   jump guy_3_path
              "I'm actually fine with being a teacher.":
                   jump guy_1_2_path
As you can see, I'm terrible with Otome game writing, but hopefully you get the idea.
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: [Coding help] Finish 2 route to unlock secret route

#3 Post by trooper6 »

PyTom wrote: As you can see, I'm terrible with Otome game writing, but hopefully you get the idea.
I, for one, would love to play the PyTom otome: Lumberjane in Love!
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
bloodyhair
Regular
Posts: 61
Joined: Tue Aug 11, 2015 7:20 am
Deviantart: Takada-Wang
Contact:

Re: [Coding help] Finish 2 route to unlock secret route

#4 Post by bloodyhair »

PyTom wrote:I don't think that code will work. You probably want to use persistent for this.

The code needs to be distributed throughout the script. For each of the two main endings, you'll have code like:

Code: Select all

    $ persistent.unlocked_guy_1 = True
    "... and that's how I became a princess!"

Code: Select all

    $ persistent.unlocked_guy_2 = True
    "... and that's why I'm waking up with the cows each morning!"
And then you'll need to somehow make the third route conditional.

Code: Select all

    if persistent.unlocked_guy_1 and persistent.unlocked_guy_2:
        menu:
              "You know, I never wanted to do this. I wanted to be ... a Lumberjack! Swinging from tree to tree in the mighty forests of British Columbia.":
                   jump guy_3_path
              "I'm actually fine with being a teacher.":
                   jump guy_1_2_path
As you can see, I'm terrible with Otome game writing, but hopefully you get the idea.
This is interesting. I never read about the persistent code in any place before. What does this command do?
The code needs to be distributed throughout the script.
Is this mean I need to put the code in entire script.rpy? Like in prolog_script.rpy and chapter1_script.rpy? Or just in Ending_script.rpy?
I, for one, would love to play the PyTom otome: Lumberjane in Love!
And yeah, I would love to play it too …<3 <3 Tee hee

User avatar
orz
Regular
Posts: 126
Joined: Tue Apr 21, 2015 10:19 pm
Contact:

Re: [Coding help] Finish 2 route to unlock secret route

#5 Post by orz »

This is interesting. I never read about the persistent code in any place before. What does this command do?
http://www.renpy.org/doc/html/persistent.html
Is this mean I need to put the code in entire script.rpy? Like in prolog_script.rpy and chapter1_script.rpy? Or just in Ending_script.rpy?
Wherever you'd need to check if XYZ is true.
Persistent variables are just variables that don't get wiped when you start a new game or restart Renpy, so you can easily use it for unlockable things like image galleries or routes that require previous playthroughs.

User avatar
Evildumdum
Regular
Posts: 191
Joined: Sun Jan 18, 2015 8:49 am
Projects: ApoclypseZ
Contact:

Re: [Coding help] Finish 2 route to unlock secret route

#6 Post by Evildumdum »

Ooooh, useful. Great if you want a game with a CG gallery that is accessible from the main menu and unlocks during gameplay. I'll have to bear that in mind. Also, its less classy than using persistents, but you could always create a character choice screen that appears after you start the game. It would be easy to redirct the player back to the character choice screen after they clear a route instead of sending them to the main menu. A simple $ route1_cleared = True and $ route2_cleared = True variable placed at the end of each route would allow you to make the third route appear after they cleared both routes easily.
Last edited by Evildumdum on Mon Aug 31, 2015 7:02 pm, edited 1 time in total.
"If at first you don't succeed, try hitting it with a shoe."

User avatar
bloodyhair
Regular
Posts: 61
Joined: Tue Aug 11, 2015 7:20 am
Deviantart: Takada-Wang
Contact:

Re: [Coding help] Finish 2 route to unlock secret route

#7 Post by bloodyhair »

Wherever you'd need to check if XYZ is true.
By XYZ you mean the result of the coding?

And I found this code called MultiGame.Persistence. Do you think I can use it for making a lockable character story?

Code: Select all

init python:
    mp = MultiPersistent("ending.org")

label start:

    # ...

    # Record the fact that the user finish the ending.

    $ mp.ending = True
    $ mp.save()

    e "You end this story! Now you unlocked new story!"

Code: Select all

init python:
    mp = MultiPersistent("ending.org")

label start:

    if mp.ending :
         e "New Character Unlocked"
    else:
         e "Please unlock the good ending of another route first."
And also I forgot to ask. What is .org and how can you get it? Is that different than .rpy?

User avatar
orz
Regular
Posts: 126
Joined: Tue Apr 21, 2015 10:19 pm
Contact:

Re: [Coding help] Finish 2 route to unlock secret route

#8 Post by orz »

A simple $ route1_cleared = True and $ route2_cleared = True variable placed at the end of each route would allow you to make the third route appear after they cleared both routes easily.
Yes, but... then the player has to beat both routes on the same save file, before that third route would pop up. And it'd only pop up on that save file - starting a new game wouldn't show the third route.
By XYZ you mean the result of the coding?
No, by XYZ I mean whatever variable it is you need to check, not the result of the code itself. Do you need to check if the player has already seen this route? Do you need to check if affection points are high enough to unlock the other menu option? Things like that.
And I found this code called MultiGame.Persistence. Do you think I can use it for making a lockable character story?
From the documentation: "Multi-Game persistence is a feature that lets you share information between Ren'Py games."

As in, a completely different game. A different project. Like if you wanted to add in a little bonus if someone played another one of your games already, that'd be something you would use.
And also I forgot to ask. What is .org and how can you get it? Is that different than .rpy?
I'm pretty sure "demo.renpy.org" used in the example is just an example of a string, rather than a specific file. Renpy.org is the official website for Renpy, after all, and I think demo.renpy.org may have been what games.renpy.org is now.

User avatar
bloodyhair
Regular
Posts: 61
Joined: Tue Aug 11, 2015 7:20 am
Deviantart: Takada-Wang
Contact:

Re: [Coding help] Finish 2 route to unlock secret route

#9 Post by bloodyhair »

Then the code I wrote should be like this?

Code: Select all

 if persistent.GoodEd1 and persistent.GoodEd2 = True:
    persistent.SecretRoute = True

if persistent.SecretRoute = True:
    e "congratulation! You unlocked secret route!"
    else:
        "To unlock this secret route, please get the good ending of two other characters."

User avatar
orz
Regular
Posts: 126
Joined: Tue Apr 21, 2015 10:19 pm
Contact:

Re: [Coding help] Finish 2 route to unlock secret route

#10 Post by orz »

Well, the "else" has to be on the same indentation as the "if" it's a part of.

Other than that, looks fine.

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: [Coding help] Finish 2 route to unlock secret route

#11 Post by trooper6 »

Things to remember/note:
1) you use = to assign a value, and == to compare values.
2) assigning values is a python statement, so it needs to have $ in front of it
3) When using if statements with more than one condition, both conditions must be written out fully
4) The else should be on the same indentation level as the if it is paired with

So your code should look like this

Code: Select all

if persistent.GoodEd1 == True and persistent.GoodEd2 == True:
    $ persistent.SecretRoute = True

if persistent.SecretRoute == True:
    e "congratulation! You unlocked secret route!"
else:
    "To unlock this secret route, please get the good ending of two other characters."
If you look at your code, you can see that it is inefficient. You don't actually need persistent.SecretRoute, you could just write:

Code: Select all

if persistent.GoodEd1 == True and persistent.GoodEd2 == True:
    e "congratulation! You unlocked secret route!"
else:
    "To unlock this secret route, please get the good ending of two other characters."
I notice I didn't see you assigning the persistent.GoodEd1 and persistent.GoodEd2 values anywhere, so make sure you do that after the routes are finished.

If you haven't done it, I highly recommend taking the free Beginners Python course from codeacademy.com
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
orz
Regular
Posts: 126
Joined: Tue Apr 21, 2015 10:19 pm
Contact:

Re: [Coding help] Finish 2 route to unlock secret route

#12 Post by orz »

trooper6 has it right. I just kinda glanced at it, so I missed a bit of stuff.

User avatar
bloodyhair
Regular
Posts: 61
Joined: Tue Aug 11, 2015 7:20 am
Deviantart: Takada-Wang
Contact:

Re: [Coding help] Finish 2 route to unlock secret route

#13 Post by bloodyhair »

Thank you so much for your help trooper6! <3

Now I am guessing this code is written at script.rpy in the very beginning of secret route script?

Code: Select all

if persistent.GoodEd1 == True and persistent.GoodEd2 == True:
    e "congratulation! You unlocked secret route!"
else:
    "To unlock this secret route, please get the good ending of two other characters."
I notice I didn't see you assigning the persistent.GoodEd1 and persistent.GoodEd2 values anywhere, so make sure you do that after the routes are finished.
Yeah I am planning to write it down like this for entire script, except secret route.

Code: Select all

 $ persistent.GoodEd1 = False
and write this down in the end of good ending script.

Code: Select all

 $ persistent.GoodEd = True 
If you haven't done it, I highly recommend taking the free Beginners Python course from codeacademy.com
Thank you so much! I will check and learn it asap! >:3

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: [Coding help] Finish 2 route to unlock secret route

#14 Post by trooper6 »

bloodyhair wrote:Thank you so much for your help trooper6! <3

Now I am guessing this code is written at script.rpy in the very beginning of secret route script?

Code: Select all

if persistent.GoodEd1 == True and persistent.GoodEd2 == True:
    e "congratulation! You unlocked secret route!"
else:
    "To unlock this secret route, please get the good ending of two other characters."
It is sort of hard to say...because I don't really know how you are organizing your game. How you would do it would depend a bit on how your game works. But here is a complete game that uses persistent. You can make a new project and paste this into script.rpy so you can see how it works:

Code: Select all

# You can place the script of your game in this file.

# Declare images below this line, using the image statement.
# eg. image eileen happy = "eileen_happy.png"

# Declare characters used by this game.
define e = Character('Eileen', color="#c8ffc8")
define a = Character('Abe', color="#c8ffc8")
define b = Character('Brody', color="#c8ffc8")
define c = Character('Chuck', color="#c8ffc8")

init python:
    if not persistent.GoodEd1:
        persistent.GoodEd1 = False
    if not persistent.GoodEd2:
        persistent.GoodEd2 = False

# The game starts here.
label start:
    "It is the first day of your. You walk into the grad student lounge. There are some students in the lounge already."
    menu:
        "Who do you want to talk to?"
        "The slim and nerdy looking fellow.":
            jump abestory
        "The beefy, bro looking fellow.":
            jump brodystory
        "The guy that looks just like Ryan Gosling." if persistent.GoodEd1 == True and persistent.GoodEd2 == True:
            jump chuckstory
            
label abestory:
    "You chat with Abe and fall in love. You have a hard time finding jobs at the same university after you both graduate...but still you are happy."
    $persistent.GoodEd1 = True
    return
    
label brodystory:
    "You chat with Brody and fall in love. He quits academia and becomes a stay at home dad while you work on getting tenure."
    $persistent.GoodEd2 = True
    return
    
label chuckstory:
    "You chat with Chuck and fall in love. Whatever fantasy you have about relationships, this fulfills it."
    return
    
If you were doing a point based plot you'd probably structure it a bit differently...but that is a basic skeleton.
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
bloodyhair
Regular
Posts: 61
Joined: Tue Aug 11, 2015 7:20 am
Deviantart: Takada-Wang
Contact:

Re: [Coding help] Finish 2 route to unlock secret route

#15 Post by bloodyhair »

Code: Select all

# You can place the script of your game in this file.

# Declare images below this line, using the image statement.
# eg. image eileen happy = "eileen_happy.png"

# Declare characters used by this game.
define e = Character('Eileen', color="#c8ffc8")
define a = Character('Abe', color="#c8ffc8")
define b = Character('Brody', color="#c8ffc8")
define c = Character('Chuck', color="#c8ffc8")

init python:
    if not persistent.GoodEd1:
        persistent.GoodEd1 = False
    if not persistent.GoodEd2:
        persistent.GoodEd2 = False

# The game starts here.
label start:
    "It is the first day of your. You walk into the grad student lounge. There are some students in the lounge already."
    menu:
        "Who do you want to talk to?"
        "The slim and nerdy looking fellow.":
            jump abestory
        "The beefy, bro looking fellow.":
            jump brodystory
        "The guy that looks just like Ryan Gosling." if persistent.GoodEd1 == True and persistent.GoodEd2 == True:
            jump chuckstory
            
label abestory:
    "You chat with Abe and fall in love. You have a hard time finding jobs at the same university after you both graduate...but still you are happy."
    $persistent.GoodEd1 = True
    return
    
label brodystory:
    "You chat with Brody and fall in love. He quits academia and becomes a stay at home dad while you work on getting tenure."
    $persistent.GoodEd2 = True
    return
    
label chuckstory:
    "You chat with Chuck and fall in love. Whatever fantasy you have about relationships, this fulfills it."
    return
   
This looks very good <3 thank you very much

Post Reply

Who is online

Users browsing this forum: Google [Bot]