Best way to make a chapter select work (while retaining variables?)

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
trailsiderice
Regular
Posts: 69
Joined: Fri Sep 29, 2023 4:02 pm
Contact:

Best way to make a chapter select work (while retaining variables?)

#1 Post by trailsiderice »

So, I want to have a set-up where I have different routes. Once the player goes through the prologue, they can then select a character route, and each character's route menu has a list of chapters that unlock as the player goes through them, and at any point the player can replay different chapters or continue from where they left off. While playing each chapter, when the end of a chapter is reached, I want the player to be able to choose whether they want to continue to the next chapter or go back to the main menu (and potentially continue later)

Here's where I start to have a problem. Right now the way I have this set up is that each chapter start button just starts the game from the beginning label of that chapter, and the final label in the rpy file just ends the game and sends the player back to the main menu if the player doesn't choose to continue. To get later chapters to remember variables declared in earlier chapters, I've been using persistent data. But that feels like an abuse of the persistent data system. What I want to do is also utilize save data somehow, so that certain variables declared in one chapter can be used in later chapters without having to declare them as persistent data. (Because with my current setup, variables from chapter 1 or even in the prologue will not be remembered in later chapters without persistents)

I have a bit of trouble fully understanding how Ren'Py save data works, (it kind of seems like it's not really built for the purpose I'm trying to use it for?) so I'm not sure how to implement this in a way that will accomplish what I want. I don't want there to be a save select menu at all (i plan on removing it). I want players to be able to select a chapter and it loads the appropriate chapter while remembering variables from earlier chapters. I imagine this system to have almost branching save data—such that variables declared in the prologue affect all of the routes, but each route has it's own separate save "branch" with it's own variables that don't cross over into the other routes.

I don't know if I'm making sense here. Hopefully I'm getting across what I mean? Is this possible with save data, or should I stick with using persistent variables for the stuff that's important?

User avatar
m_from_space
Miko-Class Veteran
Posts: 975
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Best way to make a chapter select work (while retaining variables?)

#2 Post by m_from_space »

I think you have to first understand the difference between persistent data and game data.

Persistent data is shared across all games (and players on the same PC). Game data only refers to a specific game, that is currently running (either loaded or just started). For each game you start, new "game data" is created using the "default" values. And on each game load, Renpy loads the last state of those variables when saved.

Persistent data can be used when you are outside of a game, like in the main menu. Game data cannot be used outside of a running game, at least it doesn't make any sense.
trailsiderice wrote: Wed Jan 03, 2024 7:14 pmTo get later chapters to remember variables declared in earlier chapters, I've been using persistent data.
That's not necessary and also wrong. You can just use a game variable to store what was chosen in earlier chapters. But remember, you cannot use this information inside the main menu.

If you want to use information inside the main menu (meaning outside of the game, when it's not running), you *have to* use persistent data.
Right now the way I have this set up is that each chapter start button just starts the game from the beginning label of that chapter...
This will create new game data for each chapter, it's like starting individual games. At least if you're using "Start()" when the player clicks the button.

I suggest putting your chapter select not in the main menu, but the start label. So every player (e.g. a brother and a sister on the same machine, playing your game) has their own chapter select. You can then store chosen chapters inside a list of whatever. And instead of returning to the main menu, you return to the start label. From there the player can also "quit" of course (returning to the main menu).

Code: Select all

default chosen = []

label start:
    "Please choose your path!"
    menu:
        "Chapter 1" if "chapter1" not in chosen:
            $ chosen.append("chapter1")
            jump chapter_one
        "Quit":
            pass
    return
When a player wants to resume their game, they just can use the proper method: loading it.

I think your big misconception (or let's say your point of view) is that your game on one machine will ever be used by one player only. It's not invalid and probably likely, but this will make your head spin when thinking about persistent data and game data. It's easier to assume multiple players will use your game on one machine. Build your game for them!

trailsiderice
Regular
Posts: 69
Joined: Fri Sep 29, 2023 4:02 pm
Contact:

Re: Best way to make a chapter select work (while retaining variables?)

#3 Post by trailsiderice »

m_from_space wrote: Thu Jan 04, 2024 4:28 am I think your big misconception (or let's say your point of view) is that your game on one machine will ever be used by one player only. It's not invalid and probably likely, but this will make your head spin when thinking about persistent data and game data. It's easier to assume multiple players will use your game on one machine. Build your game for them!
I'd actually prefer to have it so that it's only one save data per machine, in this case. Usually I would agree with you, but in this particular case, there is a very specific reason that is important to me and the story itself for why it should be set up this way, and so I'm not really looking for advice on whether or not I *should* do it the way that I am doing it.
m_from_space wrote: Thu Jan 04, 2024 4:28 am I suggest putting your chapter select not in the main menu, but the start label. So every player (e.g. a brother and a sister on the same machine, playing your game) has their own chapter select. You can then store chosen chapters inside a list of whatever. And instead of returning to the main menu, you return to the start label. From there the player can also "quit" of course (returning to the main menu).
So, this might not necessarily be a bad idea—while my chapter select menu is a special menu screen designed to be part of the main menu, with a few tweaks I might be able to make it so that it's shown within a label in such a way that fools the player into thinking theyre still on the main menu. However there's a couple things I'm struggling to wrap my brain around...

number one, loading vs starting. My understanding is that "start" and "load" are separate functions. In order to make this work seamlessly (without a save slot screen, which is something I'm dead set on not having, sorry, you won't convince me otherwise) I will need the same button to be able to both start the game if no save data exists, and also load the relevant save data if it does. Can this be done?

number two, what about saving within chapters? What I'd like to do is have it set up so that the player can leave back to the chapter select menu (and potentially the real main menu) and then re-enter the same chapter by selecting the chapter in question from the chapter select menu, and they will find themselves at approximately the same spot they were before exiting to the chapter select. (not exactly the same spot, probably at least a few lines before, but around the same spot) Is this something I could do with that setup?

User avatar
m_from_space
Miko-Class Veteran
Posts: 975
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Best way to make a chapter select work (while retaining variables?)

#4 Post by m_from_space »

trailsiderice wrote: Thu Jan 04, 2024 9:03 pm number one, loading vs starting. My understanding is that "start" and "load" are separate functions. In order to make this work seamlessly (without a save slot screen, which is something I'm dead set on not having, sorry, you won't convince me otherwise)
Alright, this basically means that you don't want your player to be able to save different states of the game, but only ever have one big save slot available, that is handled automatically. I mean it's possible, just... strange. No turning back so to speak. No possibility to save somewhere, try out a path and maybe reload a state before that path. Am I right? It's "commitment" mode, so to speak.
I will need the same button to be able to both start the game if no save data exists, and also load the relevant save data if it does. Can this be done?
Yes it can be done. You just focus on a single save game, that you name yourself and handle yourself via renpy.save() and renpy.load(). Save the game automatically, when the player quits (before entering the main menu I mean), and load it when the player resumes.
number two, what about saving within chapters? What I'd like to do is have it set up so that the player can leave back to the chapter select menu (and potentially the real main menu) and then re-enter the same chapter by selecting the chapter in question from the chapter select menu, and they will find themselves at approximately the same spot they were before exiting to the chapter select. (not exactly the same spot, probably at least a few lines before, but around the same spot) Is this something I could do with that setup?
I'm not sure I'm following and I understand why you are confused, because it's a confusing system. I think you would need to lay out what kind of data is important at that stage.

trailsiderice
Regular
Posts: 69
Joined: Fri Sep 29, 2023 4:02 pm
Contact:

Re: Best way to make a chapter select work (while retaining variables?)

#5 Post by trailsiderice »

m_from_space wrote: Fri Jan 05, 2024 8:58 am Alright, this basically means that you don't want your player to be able to save different states of the game, but only ever have one big save slot available, that is handled automatically. I mean it's possible, just... strange. No turning back so to speak. No possibility to save somewhere, try out a path and maybe reload a state before that path. Am I right? It's "commitment" mode, so to speak.
Sort of, but also not quite. I'm thinking of something sort of similar to how saves are handled in some mobile visual novels such as "The Arcana" and "Fictif". In those games, you don't have a save menu. Instead, the player plays through a route, and unlocks chapters as they go, and can replay each chapter at any time via the chapter select menus.

In The Arcana for example, when they finish a chapter, their progress is saved, but at any point they can go back through the same chapter by reselecting it in the chapter select menu and playing it again, even if they have not finished the entire route yet. This way, they can try out different paths within each chapter, or for larger scale things (such as unlocking good/bad endings) they don't necessarily need to replay through the whole game again just to get the bad ending for example, they only need to replay through enough of the past chapters to change enough necessary variables for the good/bad end and unlock the branching ending chapters.

Fictif's system is closer to what I think you're imagining—it's similar to The Arcana's but differs in that, while players can go back and reread chapters at any time, and play different branching paths within a chapter, the game only remembers the first playthrough's choices between chapters. (e.g. if you replay chapter 1 and choose different choices, it will only remember your new choices for the duration of chapter 1, and choices that might have affected chapter 2 will not change chapter 2 if you choose to replay that) in order for variable changes to be saved so that they can affect later chapters, the player has to reset the entire route by clicking a "Reset Story" button at the bottom of the chapter select, and replay from the beginning. However even with Fictif, players can still try out different paths without starting over (although it's mostly just different paths within single chapters)
m_from_space wrote: Fri Jan 05, 2024 8:58 am I'm not sure I'm following and I understand why you are confused, because it's a confusing system. I think you would need to lay out what kind of data is important at that stage.
I guess what I mean is that, if the chapter select menu is within the game itself, rather than being on the main menu, and the player backs out of a chapter and wants to re-enter it, I'd like to remember at least which label the player was on. I wasn't really sure I'd be able to load that save while the game is still in session, but now that I think about it, I'm pretty sure it's still possible to load a save even from within gameplay (rather than just from the main menu) so I think I just invented a non-issue to worry about.

In any case, I think I should be able to get that setup to work the way I want it to then... I'll try it out at least and see how it goes. Thanks for your help!

Post Reply

Who is online

Users browsing this forum: No registered users