How do you all keep your Renpy code organized?

TacoHoleStory

Member
May 11, 2021
128
270
I have close to 2000 lines of code now and I find my eyes glazing over trying to focus and find things, despite having split the code into about 10 files.

I wish I could split all the dialogue into a separate file.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,561
2,183
I wish I could split all the dialogue into a separate file.

You can.

For the most part, RenPy doesn't care what file(s) the script is stored in.

That said, there are advantages for having the whole script in a single file (mainly when using "Find" in your editor).

But if you want to split things up... you can... in any way you like.

Release your game in chapters? Call the files script.rpy, prologue.rpy, chapter01.rpy, chapter02.rpy, chapter03.rpy, chapter04.rpy, chapter05.rpy, etc.

Open world game? Call the files script.rpy, intro.rpy, mcbedroom.rpy, kitchen.rpy, livingroom.rpy, cinema.rpy, momsbedroom.rpy, sexshop.rpy, etc.

Writing a dating sim? Call the files script.rpy, backstory.rpy, common.rpy, sidequests.rpy, sarah.rpy, tessa.rpy, jenny.rpy, shaun.rpy, etc.

Beyond that, those *.rpy, can be within any subdirectory of the /game/ folder. So if you wanted to go even more granular... /game/chapter01/jenny.rpy would be just as valid as any other script filename. (I'd caution against going that granular though).

The game can't just "flow downward" as the script would now. Whereas your code for chapter3 might immediately follow chapter2 in the script, if written like this you would need to add something like a jump statement in order for the game to be able to find a label like label chapter03_start: stored within chapter03.rpy. Like the filenames... the label names can anything that makes sense to you.

You can also use alternate script filesnames for specific purposes. custom_screens.rpy, characters.rpy, animations.rpy, variables.rpy are all filenames I've used before. (I've stopped breaking code down to that level of speciality more recently, but I list them as an example of "Just because you can do a thing, doesn't mean you should do a thing").

Or mix and match any combination of these examples. RenPy doesn't care.

On a practical level, if you have already released versions of your game - then you shouldn't split it up... or at least, not the bits that already exist. Doing so would likely cause players problems loading save files.

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

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,263
15,073
[...] despite having split the code into about 10 files.

I wish I could split all the dialogue into a separate file.
Hmm, i'll complement the response you already got, because there's something odd in your question.

You separated the code into 10 files, yet you wonder if you can do the same for the dialogues, what seem odd.
I mean, if you've already split your code, you know, at least more or less, what's said in the comment above this one. But then , you shoud also know that you can split the dialogues into separate files... yet you don't.

Therefore, I assume that you're the kind of people who've 10.000 lines by files, with just 1 or 2 labels inside it. Or the kind that have more labels, but all as part of a big flow just to let different branch join when needed ; something like:
Code:
label whatever:
    [...]
    menu:
        "choice 1":
            label blabla_1:
                [...]
                jump regroup_1
        "choice 2":
            [...]
            jump regroup_1
        "choice 3":
            jump blabla_1
    label regroup_1:
        [...]
While both are perfectly legit, they also are far to be the best option, because there's too much information and it's difficult to retrieve something in particular.
You know, by example, that what you search for happen the 2 days, but your label for the second day have 25.000 lines... and it's somewhere inside this big soup.

Therefore, the first step before splitting your code into files, is to split it into labels.

Your story isn't a big sequence between two characters, captured by a single fixed camera, and that will happen during an eternal second. It's more at the opposite, a slice of life involving many characters, many locations, that will need many days to happen. This give you a first division for your labels:
  • The location change ? Poof, a new label.
  • The time advance significantly ? Poof, a new label.
  • A character replace another character as interlocutor ? Poof, a new label.
And so on.
Each time a movie director would say, "cut, take a break and we will pass to the next sequence", you have a natural place to end your current label.

This present many advantages:
  1. You have smaller labels.
    Even if the visual change with every line, 2.000 lines of code represent a ping-pong of 500 dialogues lines by character. It's enormous for the vast majority of scenes.

  2. You can write the scenes in the order you feel it.
    You've to write the first kiss scene, but right now it don't come. One hour that you're stuck with it, and you only write stupidities... Don't force it. Pass to a scene after this one, a scene that come naturally to you, and come back to this first kiss when you'll finally have it.

  3. You can (relatively) easily rearrange the order of the sequences.
    Now that you've the content in front of your eyes, a scene feel better when it happen earlier, or later ? Just change the moment you jump/call it.
    Of course, try to not do this after the update is released, and don't forget that it can change part of the dialogues of other scenes. It wouldn't feel right if a girl talk about her first kiss with MC, but the said first kiss have been finally moved after this moment.

  4. You can easily remove a scene.
    There's always a difference between what you had in your head, what you wrote in your script, and what you finally get once the content is wrote and the visual parts added. And this difference sometimes imply that a scene feel totally useless. Well, just remove the label and its content, remember to correct your jump/call, and your game don't feel odd anymore.

  5. You can easily add a scene.
    It's the opposite of the previous point. In your head, "this" felt obvious, but now that you played the whole day, it isn't anymore. You need an additional interlude to solve this problem. Well, just add the label for it, and correct your jump/call.

Of course, all this can also be done if everything is in a single big label. But to do it you've to read the whole label in order to find the right scene to remove, or the right insertion point. And when you want to move a scene, it's worse since you've to find both the scene, then the insertion point. You'll need hours to do something that need less than 2 minutes if you've a label by sequence.

And obviously, the first and most interesting advantage is the one I don't listed: It's so much easier to edit your code.
You need to correct something in the dialog that happen when MC have lunch with the girl ? It's not "somewhere, more or less in the middle of the 20.000 lines label for the day X", it's in the, probably less than, 500 lines of the "dayX_lunchWithGirl" label.


Then, once you've your code split in a bunch of small labels, you can arrange them like you want in multiple files, depending of the nature of your game. And this, 79flavors already explained it perfectly.
 
Last edited:
  • Like
Reactions: Beethoven9

Affogado

Newbie
Game Developer
Jun 12, 2021
69
97
What little work I've done in Ren'Py pretty much follows the advice of the posters above. I keep my individual files very focused and use subfolders to group them according to whatever structure I'm working with is.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,263
15,073
Here's an example of how I've structured things (labels minimized obviously):
Well, seem good for me.
The labels can possibly have more explicit names, but it's not always easy to do ; there's case where you've not really the choice and either be too vague or too explicit. But globally is relatively well ordered and split.

Eventually, put everything to an higher level of indentation.
I never tried this, but normally if you really move everything except the comments, Ren'py should not complain. Something that would looks like that:
Code:
# Initalization
    init python:
        [...]

    style [...]
    default [...]

# kitchen
    label whatever:
        [...]

# bathroom
    label whatever:
        [...]
With the help of code folding, it should create new virtual blocks based on the comment. But it's not necessarily needed.


This being said, due to the way your code looks, your difficulties looks more like a question of habit. With time it should be better.
 
  • Like
Reactions: Alex29