Cutting the code into different modules for ease of access?

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
Argeus_the_Paladin
Veteran
Posts: 264
Joined: Sat Feb 26, 2011 9:36 am
Projects: Rzeczpospolita Polska 1647
Location: Κωνσταντινούπολη, Βασιλεύα των Ρωμαύων
Contact:

Cutting the code into different modules for ease of access?

#1 Post by Argeus_the_Paladin » Mon Jul 02, 2012 7:42 am

As at present, my code is approaching the 7000 mark, and it is becoming harder and harder to properly navigate it. For practical reason, I am considering dividing it into different modules and import them into the main module when the game is run. However, I didn't understand the relevant instruction in the documentation.

Could anyone give me a brief run-through of what I need to keep in mind if I want to do this?
One Province Minor - 120 class variables and still counting!

Because there is no such thing as too many variables.

User avatar
Showsni
Miko-Class Veteran
Posts: 563
Joined: Tue Jul 24, 2007 12:58 pm
Contact:

Re: Cutting the code into different modules for ease of acce

#2 Post by Showsni » Mon Jul 02, 2012 11:05 am

Why not just use different script files? It's got to be easier than trying to make and import modules...

Ren'Py will run any script files it finds in the game folder, so you can just save different parts of your code to different ones and give them names to help you keep things in order.

Argeus_the_Paladin
Veteran
Posts: 264
Joined: Sat Feb 26, 2011 9:36 am
Projects: Rzeczpospolita Polska 1647
Location: Κωνσταντινούπολη, Βασιλεύα των Ρωμαύων
Contact:

Re: Cutting the code into different modules for ease of acce

#3 Post by Argeus_the_Paladin » Mon Jul 02, 2012 11:59 am

That's exactly what I am looking for, right there.

Is there any pointer on how the program loads codes in different script files? Or any tutorial I could read about this?
One Province Minor - 120 class variables and still counting!

Because there is no such thing as too many variables.

User avatar
Showsni
Miko-Class Veteran
Posts: 563
Joined: Tue Jul 24, 2007 12:58 pm
Contact:

Re: Cutting the code into different modules for ease of acce

#4 Post by Showsni » Mon Jul 02, 2012 12:48 pm

Argeus_the_Paladin wrote:That's exactly what I am looking for, right there.

Is there any pointer on how the program loads codes in different script files? Or any tutorial I could read about this?
I'm not sure of the specifics, but I believe anything in an init block (regardless of file) will run first. You shpuld only have one start label (or you'll get an error) amongst all the files, and the game will start there. And you can jump to or call any label, regardless of which file it's in.

Argeus_the_Paladin
Veteran
Posts: 264
Joined: Sat Feb 26, 2011 9:36 am
Projects: Rzeczpospolita Polska 1647
Location: Κωνσταντινούπολη, Βασιλεύα των Ρωμαύων
Contact:

Re: Cutting the code into different modules for ease of acce

#5 Post by Argeus_the_Paladin » Mon Jul 02, 2012 12:53 pm

So in file 1 we can have:

Code: Select all

init python:
    # part 1 definitions go here
and in file 2, 3, 4, 5,... n we have:

Code: Select all

init python:
    # part 3, 3, 4, 5, ...n definitions go here
The question is, should all of these files end with return? From dissecting the tutorial it seems to be the case, but there is also the thing that each tutorial modules actually concludes with jumping back to the main tutorial game menu.

So what should it be?
One Province Minor - 120 class variables and still counting!

Because there is no such thing as too many variables.

User avatar
ScottySeng
Regular
Posts: 162
Joined: Tue Oct 04, 2011 9:57 am
Completed: May-Chan
Projects: Fairy Tale, What do you see
Skype: scottyseng
Location: Carrollton, TX
Contact:

Re: Cutting the code into different modules for ease of acce

#6 Post by ScottySeng » Mon Jul 02, 2012 3:34 pm

http://lemmasoft.renai.us/forums/viewto ... =8&t=14222

I think the middle of this thread may help. It's about splitting Renpy files.

User avatar
Alex
Lemma-Class Veteran
Posts: 2981
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Cutting the code into different modules for ease of acce

#7 Post by Alex » Mon Jul 02, 2012 4:20 pm

The question is, should all of these files end with return? From dissecting the tutorial it seems to be the case, but there is also the thing that each tutorial modules actually concludes with jumping back to the main tutorial game menu.
No. The structure of tutorial game code is - the menu in start label from which different chapters are called, so at the end of this chapters should be a return command (to put player back to menu).
In your case, no returns are needed. Just split you code to several rpy-files with its own init blocks screens and ATL definitions and so on. When you'll run your game, Ren'py will treat all this rpy-files as one big file and will execute all init blocks first and start label then.
http://www.renpy.org/wiki/renpy/FAQ#How ... e_files.3F

Argeus_the_Paladin
Veteran
Posts: 264
Joined: Sat Feb 26, 2011 9:36 am
Projects: Rzeczpospolita Polska 1647
Location: Κωνσταντινούπολη, Βασιλεύα των Ρωμαύων
Contact:

Re: Cutting the code into different modules for ease of acce

#8 Post by Argeus_the_Paladin » Mon Jul 02, 2012 8:42 pm

So if I understand correctly, splitting the script into different files have virtually no effect on how it is run, but only how it is organized?

That's perfect. Thanks for the pointer, everyone. :D
One Province Minor - 120 class variables and still counting!

Because there is no such thing as too many variables.

Post Reply

Who is online

Users browsing this forum: Bing [Bot]