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.

Runtime init blocks

The biggest advantage of init: and init python: blocks is the fact that they are run automatically each time the game is run - and they can be spread around different files. The biggest disadvantage of them is the fact that variables created in init blocks are not saved (and don't participate in rollback) until you assign them a new value outside of an init block - in the runtime. After assigning them a new value, they work correctly and all changes will be tracked (even state inside objects, like state.love_love_points = a + 1). The following should be placed inside (for example) a 00initvars.rpy file:

# this file adds a function that sequentially calls
# all __init_variables labels defined in your *.rpy
# files

init python:
    def init_variables():
        initvarlabels = [label for label in renpy.get_all_labels() if label.endswith('__init_variables') ]
        for l in initvarlabels:

To use this file, simply add a call to the init_variables function to the start and after_load labels of your game:

label start:
    $ init_variables()
    # your normal code here

label after_load:
    $ init_variables()
    # your normal code here

To define an init block, simply create an __init_variables label in your files (don't worry about it being called the same in each file, RenPy automatically replaces the double underscore with a unique prefix based on the file name). Important: Don't forget the hasattr condition for each of your variables. Otherwise, all your saved variables will be overwritten every time the game starts!

label __init_variables:
        if not hasattr(,'a_list'): #important!
            a_list = []
        if not hasattr(,'stats_dict'): # important!
            stats_dict = {