Ren'py and multiple storylines

Niteowl

Member
Game Developer
Apr 6, 2018
297
373
First of all, let me clarify I'm an absolute beginner (although I did a little coding and I think I can figure it out over time)

Anyways.... right now I'm writing a script for a visual novels and working on game mechanics etc.
So, I will work hard on learning more coding soon, but right now my question is just regarding whether I can or cannot do certain things with Ren'py....
(and maybe how hard they are to do and what kind of resources I should look at to figure things out.....) so that I can design my game on paper before I do the coding itself.

Forgive me if I have to put things into very simple terms but I am, as stated, a beginner... (mostly a writer and at times 3D artist)

let's say I have a HOME MENU - and from that I want to have two independent stories begin......let's say A and B
I guess I could make paths for both stories.....but let's say that, as a player, I go down one path, maybe A.
Ok, eventually I go back to the main Menu and try the other story - B
If I just set the code up so the player can go back to the menu....if he clicks on A I assume A will just start from the beginning again....

Is it possible to have the game remember how far along a player has already moved in a story so that from the main menu, next time he clicks on A, he will just continue from where he left off? (I would think it is, but also, how hard is it to do?)

It might sound a little stupid but I have a lot of stuff to figure out....please help me out.
 

Catapo

Member
Jun 14, 2018
232
428
Yes it is possible and overall shouldn't be that difficult. The idea is to use a file or separate files to save some sort of data(depends on your game) that represents the progress in each story like a save file of sorts.

Note that it doesn't have to work like a classic save file where the player manually saves and loads it can work more like an auto-save where you save data in the file at certain points in the story or when the player goes back to the menu and loads that data when pressing A or B.
 

Penfold Mole

Engaged Member
Respected User
May 22, 2017
2,867
6,445
Don't bother your head with something that Ren'Py has built in by default and any player can do what you described in any Ren'Py game (that isn't FUBAR'ed by the dev himself by removing default save and load menus with infinite save slots or some other way blocked saving and loading and/or rollback) by saving and loading the game or just rolling back at any point he wants.
The most you can do to improve default save menu is to add save file naming option. Some games have it implemented and it helps to keep track on separate paths.
 
  • Like
Reactions: wurg

Niteowl

Member
Game Developer
Apr 6, 2018
297
373
Don't bother your head with something that Ren'Py has built in by default and any player can do what you described in any Ren'Py game (that isn't FUBAR'ed by the dev himself by removing default save and load menus with infinite save slots or some other way blocked saving and loading and/or rollback) by saving and loading the game or just rolling back at any point he wants.
The most you can do to improve default save menu is to add save file naming option. Some games have it implemented and it helps to keep track on separate paths.
So, are you saying that Renpy would save the progress in both storylines by default?
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,094
14,737
So, are you saying that Renpy would save the progress in both storylines by default?
He's saying that the player can have a [none infinite but still really high] number of save files. So if the player want to save the progress in both story lines, he can.
 
  • Like
Reactions: Penfold Mole

deusexvagina

Newbie
Game Developer
Aug 15, 2019
54
416
You can always use a global variable like "default hasCompletedPathA = True" and ask for that in the menu. I use a similar concept to change the main menu screen on hover above the start button as a little gimick, the same could be used to determine a path for the story to take. Pretty much everything in RenPy is customizable and can listen to global variables, it's very neat.
 

wurg

Active Member
Modder
Apr 19, 2018
705
1,628
Beings you are a beginner, the simplest way is to let the user save his progress with save files in the different paths. The most helpful thing you can do with different paths is to include a naming scheme with the save files so a user can name the file themselves, I find this very handy in games.

The downside to what you are saying of having the game determine how far down the path the user is and put them back in that place is, what if the user wants to start over and play the same path again? How would they do this if the game jumps them to where they left off? It could be done with another question and variable without too much difficulty, but why complicate it further. The whole point is to let the user decide what they want to do, not to decide for them.

Like Penfold said, the best thing you can do is to code a naming system for the save files, users are used to loading saves from where they left off, it's really not a big deal.

Your first game, keep it as simple as possible, don't overwhelm yourself, it's easy to do. The code rabbit hole runs deep.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,555
2,170
It's difficult to imagine why you need an "Story A" and "Story B" from the main menu.

But maybe a little background to how RenPy saves and load (from my limited perspective) may help.

When RenPy loads a save, it tries to match the exact statement where the save took place to the same statement in the current version of your game/source code. It doesn't matter if you've added a bunch of lines, or even changed the line in question a bit. It does it's RenPy voodoo and figures it out as best it can.
If the exact line can't be figured out, then it has a log of the recent statements executed before the game was saved too. It backtracks through that list - trying to match one of those statements/commands from the recent history log to lines of code in your game right now. Again, if it can find a match... it'll go back to that line and carry on.
Sometimes even that isn't enough and RenPy will crap itself. Such is life.

So if your player starts playing "Story A"... then they're running your code... line by line, statement by statement. When the player saves... the line they are current on is part of the "Story A" code. The player quits, comes back later... and loads their saved game... it'll return to wherever the player was up to within your "Story A" dialogue.

Likewise for Story B.

If they are a separate as you are implying... then RenPy's saves will take care of keeping the player in the right story without you taking any action.

However... if... like so many other games, there's an overlap of story. Perhaps a single core story with branches that sometimes take you through unique elements of Story A or elements of Story B... or again, an overlap of the two... Then to be honest, the same is true. The player saves... the player loads... the player continues from wherever they were up to, with the game state being whatever it was in as the player saved.

Where you'd track things is those branches. If the player spies on his mom in the shower, you'd normally have a variable that acknowledges that and lets the code "know" that later on... make decisions based on that choice.
For something like that... you'd usually use a boolean variable (True/False) to remember the player choice.
Something like:
Python:
default day01_saw_mom_in_the_shower = False

label start:

    menu:
        "Spy on mom":
            $ day01_saw_mom_in_the_shower = True
            jump d01_spy_on_mom

        "Don't spy on mom":
            $ day01_saw_mom_in_the_shower = False


label d01_don't_spy_on_mom:

    # blah blah
    jump d01_continue_after_spy_on_mom


label d01_spy_on_mom:

    # blah blah


label d01_continue_after_spy_on_mom:

    if day01_saw_mom_in_the_shower == True:
        "I spied on mom."
    else:
        "I didn't spy on mom."

    return
Without really understanding why you want "Story A" and "Story B" from the main menu... I'd offer the option that you could just have a variable or variables to track which story you are actively playing and maybe have the first choice of the game as being whether to play A or play B... which tends to be how authors handle things like multiple chapters, when a player can choose to skip chapters and just play the one they are interested in.

I'm going at bit around the houses on this one, so hopefully there's something useful in there for you. It's just difficult to see the reasoning for the design choices you seem to be trying to make.
 
  • Like
Reactions: anne O'nymous

Niteowl

Member
Game Developer
Apr 6, 2018
297
373
Well, thanks for the replies guys....
I'm still a little confused and I will have to reread your posts and maybe try and code a bit to really grasp some points but it was really helpful, thanks.
However, I also think maybe I should explain what I would like to do a little better.....
(and of course in Renpy I'm a beginner, although I have done a little coding...just simple stuff like getting the player to choose a name and then a few screens)

So....
Here's the thing
I'd like to make a game that combines a main storyline and some elements of sandbox/trainer games

to be more specific, the actual novel (but still with choices etc) would be what I called Story A in the example....and other stories, involving interacting with girls in the harem/training etc, would be more like the B story in the example
Yes, some bits of those stories might end up affecting the main plot as well, and that would have to come down to variables I guess (not too worried about that yet..... I'd like to make a good beginning first of all...) but I was looking at other ways to create various paths and options for the player.
I'm a beginner when it comes to coding/creating game mechanics, so maybe I'm just being stupid maybe, but I thought I could do something like this:

For Example -

Home Menu (when the MC is in his residence)
- Town (to go to a list of locations or map)
- World Map (same but for the fictional continent where the story begins - anyways not really used at first)
- Girls/Harem whatev (mostly working on the actual stories on paper now, game mechanics I just started refining)

So, I was thinking that
The MC could move around the town, and eventually events, dialogues, encounters etc will help him/her proceed with the main story....
I think this part would be easily saved automatically by Ren'py, as long as the story itself is fairly linear (with many paths and choices, of course, but eventually reconnecting etc).... because it would be part of a fairly linear series of statements....
I understand Renpy would save the last saved statement....

On the other hand, let's say the MC decides to stay home for a bit and play with some of the girls etc
clicking on the menu above would send him to a page with a list of the girls.....

From there, I know different games have different approaches
Games like Slave Lords of the Galaxy and other trainers, for example, are big on the girls stats to determine what is possible or not, adding new options to the trainer parts etc.....
That is possible, although of course I have a lot to learn a lot in terms of how to implement all that.

Harem Hotel is different...and maybe a little closer to what I'd like to do (not the same though); there are stats, and I'm sure they have some effect on the game, but it feels like every girl has its own 'linear' story.....if you meet and chat with one (or buy certain equipment) you can go to the next stage and so on. Every update often adds bits to the stories of various girls.

Anyways, they're both examples and both games are actually quite different from what I'd like to do..... (although in terms of coding there might be some similarities with Harem Hotel since saves take into account the progress made with each girl).

So, let's get back to the girls.... I was thinking it would be interesting to create stories within the larger story for them....stories affected by the choices made by the player, rather than go the 'stats' route.

Like I said, I'm probably missing something, but it seems to me like ok, we click on a girl's name the first time, some choices will pop up, the path will split etc.....
But then maybe the MC gets bored or whatever, goes to town, meets somebody, whatev .....eventually he returns home and clicks on one of the girls again.
If clicking on a girl's name is the beginning of a linear path, then, I'm guessing, but correct me if I'm wrong, when I click on her name the link would take me to the beginning of the girl's story again, rather than to the point where the MC had decided to take a break and explore the town instead.
What I was trying to ask, is: how can I get the game to keep track of how the MC progressed in all those different paths? Preferably something not super-complex?
(or does it do it anyways? I really appreciated the long post about how Renpy works, found it very interesting, but I'm not sure how it applies to what I'm trying to do.....and again sorry, I'm a noob when it comes to coding)

Someone said I could set up separate saves for each path (again, maybe I misunderstood....if that's the case, my bad!)
But I don't really like that. It would be confusing for the players (normally we just save the game, not specific paths) and not very elegant... It would heighten the feeling that those sections are completely separate, which is not exactly true.
Also, on the topic of being able to restart the story with a girl, that wouldn't be a problem...... earlier saves for the whole game would easily allow to replay those parts and make different choices.

Beyond that...well, hopefully you have a better idea of what I'm trying to do. Any other suggestions? (just some general idea, and if possible some links to materials you think I should familiarize myself with)

thanks again for any help guys, much appreciated

PS Yes, it might be a bit ambitious for my first real project.......but it's the way I am: if I can't do something interesting I just won't bother. Besides, I will keep the first demo (assuming I ever complete one) fairly short. But I want to create something with the potential to keep growing until I can show the whole story I have concocted (and that I think is very interesting).
I also want to make something I would enjoy as a player, and what I described above fits the bill.

Chances are I'll eventually give up and quit, but you never know. I can be pretty stubborn at times and I do have a story I like and that will keep me motivated.
 

wurg

Active Member
Modder
Apr 19, 2018
705
1,628
You keep track of everything in a game with variables, that is how the game tells where the user is in the story in a sandbox game.

For example you have a button to click on the girl like you were talking about:
Code:
define part_one = True

textbutton "girl one" action Jump ( "girl one story")


label girl one story:

    if part_one:
        part one dialog
        $ part_one = False
        $ part_two = True
  
    elif part_two:
        part two dialog
        $ part_two = False
        $ part_three = True
  
    elif part three:
        part three_dialog
        $ part_three = False
        $ part_four = True
  
    elif part four:
        part four_dialog
It's not exact but that is the idea, you can also use a counter - girl_one = 0 - use that in the beginning of the game and add 1 to it each time the user finishes a part. For part two - if girl_one == 1 do this.

That's the basic idea of how to keep track of the where the user is, variables, everything is variables.

The best way to learn is to build it for ONE girl first. Get that working the way you want, after that it is rinse and repeat ( but with different variables for the different girls ) for however many girls you want to add. The way I learn to code is one little piece at a time, you can get lost in the big picture and if a bunch of errors come up they are harder to track down.
 

Niteowl

Member
Game Developer
Apr 6, 2018
297
373
You keep track of everything in a game with variables, that is how the game tells where the user is in the story in a sandbox game.

For example you have a button to click on the girl like you were talking about:
Code:
define part_one = True

textbutton "girl one" action Jump ( "girl one story")


label girl one story:

    if part_one:
        part one dialog
        $ part_one = False
        $ part_two = True

    elif part_two:
        part two dialog
        $ part_two = False
        $ part_three = True

    elif part three:
        part three_dialog
        $ part_three = False
        $ part_four = True

    elif part four:
        part four_dialog
It's not exact but that is the idea, you can also use a counter - girl_one = 0 - use that in the beginning of the game and add 1 to it each time the user finishes a part. For part two - if girl_one == 1 do this.

That's the basic idea of how to keep track of the where the user is, variables, everything is variables.

The best way to learn is to build it for ONE girl first. Get that working the way you want, after that it is rinse and repeat ( but with different variables for the different girls ) for however many girls you want to add. The way I learn to code is one little piece at a time, you can get lost in the big picture and if a bunch of errors come up they are harder to track down.
Sounds good, thanks. I will look for more info on this and give it a try (starting with one girl as you said)

Edit: by the way, any source you guys would recommend to learn more about using variables? Like in the cookbook or in the documentation? Thanks again for all the feedback
 
Last edited:

deusexvagina

Newbie
Game Developer
Aug 15, 2019
54
416
If I understand what you want to do correctly this should be very simple. One thing that might help you understand is this: No matter how many script files you have (for structure or different game areas) RenPy treats them all as one script. That means if you have a "chapter 1" and define a variable there you can use it in the file "chapter 2" without any tricks.

So you could just make a new script file, let's say "harem" and make a new button in the game menu. The start button does nothing other than jump to the "label start:" part, you can just make a new button that jumps to the "label harem:" or whatever.
 

Niteowl

Member
Game Developer
Apr 6, 2018
297
373
If I understand what you want to do correctly this should be very simple. One thing that might help you understand is this: No matter how many script files you have (for structure or different game areas) RenPy treats them all as one script. That means if you have a "chapter 1" and define a variable there you can use it in the file "chapter 2" without any tricks.

So you could just make a new script file, let's say "harem" and make a new button in the game menu. The start button does nothing other than jump to the "label start:" part, you can just make a new button that jumps to the "label harem:" or whatever.
I'm not sure I understand what you mean by your example......
I mean, I understand that the program treats all parts as belonging to the same script, but I don't understand how your example relates to what I'm trying to do (i need to track progress in different areas.....ok, labels apply to every part, but I still need labels or variables to help me keep track of the player's progress in every area right?
 

deusexvagina

Newbie
Game Developer
Aug 15, 2019
54
416
I'm not sure I understand what you mean by your example......
I mean, I understand that the program treats all parts as belonging to the same script, but I don't understand how your example relates to what I'm trying to do (i need to track progress in different areas.....ok, labels apply to every part, but I still need labels or variables to help me keep track of the player's progress in every area right?
Yes, but because it's all one that's super easy to do. I have a script file "global variables" in my game where I set something like progress, which team members are available and inventory of items, then you can just pull them wherever you need them.
 

Niteowl

Member
Game Developer
Apr 6, 2018
297
373
Yes, but because it's all one that's super easy to do. I have a script file "global variables" in my game where I set something like progress, which team members are available and inventory of items, then you can just pull them wherever you need them.
so how do you use labels to tract progress in the game exactly....
I mean, not detailed coding but just a brief explanation of how they work
Like, do they have variable values that change depending on what the players do, so the script can check their value when they go to certain areas and then skip to certain sections of the game accordingly?
Maybe combined with 'if' statements..... (again, just trying to understand the theory behind it, I find it helps me figure out the details if I have a clear idea of the general mechanisms involved
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,555
2,170
so how do you use labels to tract progress in the game exactly....
Essentially how you've described...

Anytime your player makes a decision you want the game to remember... you store that decision in a variable.

You can store numbers.... +1, +2, +3, etc. Add or subtract any other number to your numeric variable(s). Do maths... whatever.
You can store strings... "A", "B", "Chicken Soup", "chicken soup", or any other character you can imagine. Numbers stored within quotes are still strings. 1 is a number. "1" is a string.
You can also store what are known as boolean variables too. Usually they only have two values. True and False (note those names are case sensitive).

You'd normally use numbers for things like affection scores, or love points, or resistance or stuff like that.
You'd normally use boolean for something like "Did that happen?" type stuff... True or False.
Strings... well, it depends. For decision making, maybe something like is she wearing the "red", "green" or "gold" swimsuit?

Next... you have the impact of those variables on future content...

The simplest way to code is to do an if {something} jump {label}.
It's not the only way... You can nest (indent) code within if structures... But since you're just starting out... maybe keep things simple for a while and just jump to a label each time you want to take an action.
There are more ways of controlling your script that just if statements. But as I say, for the moment... keep it simple.

Each if recognizes previous player actions (using variables) and goes to certain points elsewhere in your code (labels) and does whatever commands you put there. A simple branching script might choose to jump to label "a" or label "b", but both "a" and "b" would jump to "c" afterwards to return to the common path. If that makes sense.

I know you didn't want detailed code... but something like:

You don't have permission to view the spoiler content. Log in or register now.
 
  • Like
Reactions: Niteowl

Niteowl

Member
Game Developer
Apr 6, 2018
297
373
Essentially how you've described...

Anytime your player makes a decision you want the game to remember... you store that decision in a variable.

You can store numbers.... +1, +2, +3, etc. Add or subtract any other number to your numeric variable(s). Do maths... whatever.
You can store strings... "A", "B", "Chicken Soup", "chicken soup", or any other character you can imagine. Numbers stored within quotes are still strings. 1 is a number. "1" is a string.
You can also store what are known as boolean variables too. Usually they only have two values. True and False (note those names are case sensitive).

You'd normally use numbers for things like affection scores, or love points, or resistance or stuff like that.
You'd normally use boolean for something like "Did that happen?" type stuff... True or False.
Strings... well, it depends. For decision making, maybe something like is she wearing the "red", "green" or "gold" swimsuit?

Next... you have the impact of those variables on future content...

The simplest way to code is to do an if {something} jump {label}.
It's not the only way... You can nest (indent) code within if structures... But since you're just starting out... maybe keep things simple for a while and just jump to a label each time you want to take an action.
There are more ways of controlling your script that just if statements. But as I say, for the moment... keep it simple.

Each if recognizes previous player actions (using variables) and goes to certain points elsewhere in your code (labels) and does whatever commands you put there. A simple branching script might choose to jump to label "a" or label "b", but both "a" and "b" would jump to "c" afterwards to return to the common path. If that makes sense.

I know you didn't want detailed code... but something like:
Cool man, thanks... this is really what I was after.

I will read the code carefully as well soon, I appreciate having an example to look at..... but either way the explanation was very useful.
It's a very good starting point...I can see I have a lot to learn but like I said this helps a lot.
Much obliged man
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,094
14,737
so how do you use labels to tract progress in the game exactly....
There's the answer gave by 79flavors , or there's the old fashioned way, still used by a lot of games :
Code:
label start:
    [...]
    menu:
        "do this":
             jump didThis
        "do that:    
             jump didThat

label didThis:
   [...]
   call commonPart
   [...]
   menu:
      "now do that":
            jump didThisThat
      "now do this":
            jump didThisThis

label didThat:
   [...]
   call commonPart
   [...]
   menu:
      "now do that":
            jump didThatThat
      "now do this":
            jump didThatThis


label commonPart:
    [...]
    return
The advantage of one way or the other, depend of the number of choice you want to offer to the player. And obviously, the more choice there's, the easier it is with the method explained by 79flavors . But there's two/three big games that achieve to works fine with this "no variable" approach.

And obviously, you can also combine the two. Having variables for the choice that concern the whole game, and going for the pure label approach for those that will just change the actual scene.
 
  • Like
Reactions: Niteowl