Page 1 of 1

Linking to other script files?

Posted: Mon May 25, 2020 12:06 am
by ForeverAScone
I was just wondering if there was a way to link to seperate script files rather than storing an entire game in one huge script file, so I can split it up chapter by chapter or something more manageable like that. Thank you :)

Re: Linking to other script files?

Posted: Mon May 25, 2020 12:18 am
by isobellesophia
Hello new user, it can be, you can create seperate files by creating a new file like for example.

script.rpy
another.rpy

Just make a new empty file and that's it.

Re: Linking to other script files?

Posted: Mon May 25, 2020 12:24 am
by Imperf3kt
As above, making a new file is all that's needed and is actually recommended for (very slight) performance improvements.

Just be sure to use labels and jumps returns etc correctly, remember that files load alphanumerically, and do not start any file names with 00

Re: Linking to other script files?

Posted: Mon May 25, 2020 12:33 am
by isobellesophia
00 is for RenPy common files, or also known as the function of the entire script when you create your first game, including all in there such as gui's, save files and etc, it fills with python codes and such.

like this one for example.

00gui.rpy
00common.rpy

Files like this, you should NEVER touch them, unless you know about the specific parts in that script, or you are a expert at python or anything else, or else, it'll break your game and the other games has been created especially, will break it.

Re: Linking to other script files?

Posted: Tue May 26, 2020 2:20 pm
by ForeverAScone
Ahh, gotcha. Thanks for the replies :)

Re: Linking to other script files?

Posted: Tue May 26, 2020 9:10 pm
by Trafagal
Imperf3kt wrote:
Mon May 25, 2020 12:24 am
As above, making a new file is all that's needed and is actually recommended for (very slight) performance improvements.

Just be sure to use labels and jumps returns etc correctly, remember that files load alphanumerically, and do not start any file names with 00
Hi,

I'm still quite new to Renpy, just to be sure i understand correctly. It doesn't matter what your file name is (as long as it does not begins with 00) If you initiate "label" or "jump", Renpy will search through the folder for existing .rpy files just to find that "jump"/"label" location, and not searching for the name of that Renpy file where the "label"/"jump" is?

For example:
In script.rpy, you wrote "jump Cafe"
In antherfile.rpy, "Label cafe"

Thank you

Re: Linking to other script files?

Posted: Tue May 26, 2020 10:22 pm
by Imperf3kt
Yes that's correct.
The script of a Ren'Py game is made up of all the files found under the game directory ending with the .rpy extension. Ren'Py will consider each of these files (in Unicode order), and will use the contents of the files as the script.

Generally, there's no difference between a script broken into multiple files, and a script that consists of one big file. Control can be transferred between files by jumping to or calling a label in another file. This makes the division of a script up into files a matter of personal style – some game-makers prefer to have small files (like one per event, or one per day), while others prefer to have one big script.

To speed up loading time, Ren'Py will compile the .rpy files into .rpyc files when it starts up. When a .rpy file is changed, the .rpyc file will be updated when Ren'Py starts up. However, if a .rpyc file exists without a corresponding .rpy file, the .rpyc file will be used. This can lead to problems if a .rpy file is deleted without deleting the .rpyc file.

Filenames must begin with a letter or number, and may not begin with "00", as Ren'Py uses such files for its own purposes.
You can read more about it here
https://www.renpy.org/doc/html/language_basics.html

Pytom has also mentioned a few things about the behaviour throughout the forum, so those are a bit harder to link for you.


Just be aware that if you name a script file something and your script ends without a return, or jump, renpy will continue the script at the next file in unicode order and this might cause issues of you have a label there that isn't supposed to come next.

Re: Linking to other script files?

Posted: Tue May 26, 2020 10:23 pm
by rayminator
here is a example

script.rpy

Code: Select all

label start:
    a "Hey Kira lets go to the cafe today."
    k "Okay Rayminator Lets go right now,"
    a "Okay lets go."
    jump cafe

another.rpy

Code: Select all

label cafe:
    a "Okay here we are at the cafe what would you like to get Kira?"
    k "Let's get some coffee and some domuts."
    a "Okay."

Re: Linking to other script files?

Posted: Wed May 27, 2020 12:13 am
by Trafagal
Thank you both! Those are very useful information~!