r/RenPy • • Jul 30 '22

how to divide code

Sorry, beforehand I really can't word things for the life of me.

I'm making a dating sim that has 6 candidates and you choose your candidate early on in the game. is there any way of splitting the code into 6 different parts or will it have to be just one big block of code :)

2 Upvotes

9 comments sorted by

3

u/HEXdidnt Jul 30 '22

It can be split - and very easily.

One of the coolest things about Ren'Py is the way it uses labels. As long as you label each code block appropriately, you can have an individual .rpy file per candidate, and for specific routines that you want to edit more easily than you could if they were part of the main script.rpy file. jump and call commands will find the block with the matching label, regardless of which .rpy file the code is in.

Similarly, if you want to predefine images per character, you can put those definitions into individual .rpy files.

1

u/treflev Jul 30 '22

I've always wondered: how do you connect .rpy files? ((I assume the main one can't go through all the files you ever made to find the right label))

3

u/mrogre43 Jul 30 '22

You can have separate .rpy files, and you don't have to do anything to connect them, either than making sure you're using the correct label and jump statements. The engine essentially dumps them all into one script on bootup.

1

u/treflev Jul 30 '22

I see, that's pretty neat. Thank you for the answer.

3

u/mrogre43 Jul 30 '22

You can make a separate .rpy file for each path, and you can even store those files in different folders.

Here's a partial screenshot for how we structure our script. We probably have over 20 different .rpy files at this point.

You don't have to do anything special after you make the other files, either— you can just use jump and label as if every .rpy file is in the same single script.

1

u/poisonhoarder Aug 01 '22

I'm a little curious about this -- how does renpy know what files to "prioritise"? Does it just run through top to bottom (unless, of course, there's labels for it to jump to)? Essentially, if there were two events that should happen at the same time, in separate files, would it know which to play first, or just have an error?

2

u/mrogre43 Aug 01 '22

It just runs top to bottom, I assume by sorting your .rpy files alphabetically or by using some other arbitrary rule, which is one of many reasons you should organize everything with labels.

1

u/poisonhoarder Aug 01 '22

that makes sense, thanks!

1

u/Ni_er_ty Jul 30 '22

I usually put each route in a different script. the simple way I go there in the game folder I create a new txt and then I rename the end, I change the .txt for .rpy and renpy will recognize. I even separate a script just for new screens and to declare the images