This page is out of date

You've reached a page on the Ren'Py wiki. Due to massive spam, the wiki hasn't been updated in over 5 years, and much of the information here is very out of date. We've kept it because some of it is of historic interest, but all the information relevant to modern versions of Ren'Py has been moved elsewhere.

Some places to look are:

Please do not create new links to this page.


Loading data from external file

This is a topic for slightly more advanced users only (those who are not afraid of python code).

Suppose you want to load some game data from an external file (think: level editor, mission specification, ...). How do you locate the file?

Make sure to put the file inside the game folder or a subfolder of the game folder. Suppose we have a file missions.txt which is located in .../game/resources/missions.txt:

How *not* to do it

The following does not work, the file won't be found:

    f = open("resources/missions.txt", "r")

You also don't want to specify an absolute path as part of "open", since it most likely will not work on any system other than yours.

To open the file and iterate over its lines you should transform the path using renpy.loader.transfn instead.

Example opening a file missions.txt located in .../game/resources

    python:
        # open the file
        f = open(renpy.loader.transfn("resources/missions.txt"),"r")
        # iterate over its lines and do something with them
        for line in f:
            do_something(line)
        # when finished, close the file
        f.close()

Example parsing missions.xml

    python:
        # import xml related libraries
        import xml.etree.ElementTree as elementtree
        # parse the missions.xml file
        tree = elementtree.parse(renpy.loader.transfn("resources/missions.xml"))