Ren'Py start with autoreload enabled

f95zoneuser463

Member
Game Developer
Aug 14, 2017
219
1,024
This keeps happening to me a lot:
  1. Ren'Py exits with exception while scripting/testing
  2. I restart the project and forget to enable SHIFT+R autoreload
  3. I keep scripting and expect Ren'Py to reload my changes in the background automatically
  4. Something isn't working the way I expect and I start looking for errors in scripts ...
  5. ... until I realize autoreload is off *rage because time wasted*
How can I force Ren'Py start a project with autoreload enabled whenever I'm in developer mode?

Tries this, does not work:
Python:
if config.developer:
    $ config.autoreload = True


After checking this var it always seems to be True. So it's the wrong switch?
So I have to find the function/flag that is called/set by pressing SHIFT+R
*sigh* Nooo! I don't want to dig through the Ren'Py source agaaaain.

How can I force enable this programmatically?

edit:
Found renpy.set_autoreload(True) after checking what's mapped to SHIFT + R in 00keymap.rpy. This leads to the function _reload_game() that calls set_autoreload(). Tested it in my project and it shows autoreload in the titlebar now ... but still doesn't reload automatically without using SHIFT + R.

edit 2:
Solved:
Python:
label splashscreen:
    if config.developer:
        # check autoreload flag to not end up in endless script reload loop
        if renpy.get_autoreload() == False:
            # enable autoreload on first start only
            $ renpy.set_autoreload(True)
            $ renpy.exports.reload_script()
        return # skip splashscreen in developer mode
    
    # actual splashscreen content goes here ...
Apparently it's required to call renpy.exports.reload_script() once.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,963
16,198
Apparently it's required to call renpy.exports.reload_script() once.
This because of the first sentence of the help regarding config.autoreload : "If True, Shift+R will toggle automatic reloading."

So, the configuration variable don't enable the auto-reload, it just make it an usable feature. To enable it, you either use the keys combination, or call the function behind the said keys combination.

On a side note, normally you don't need to pass through the "exports" module. renpy.reload_script() should works as well. The same applying for every function/object declared in the said "exports" module.