Ren'Py Shipping your game with saves

Cipheos

Young & Naughty's magician
Donor
Game Developer
Jan 14, 2018
193
262
Hey guys! I'm not sure if this is the right forum for this, but I spent the last two evenings trying to include saves in my Ren'Py game. Turns out Ren'Py really does not want you to package saves, and even if you can manage that you still can't load them on Android. What a pain!

The reason I wanted to do this is because I want to offer players to skip ahead to different states in the game. I notice a lot of games do this by setting variables to match a certain state of the game, but that seems error prone to me.

It seemed impossible to find any similar queries online. Fortunately the way Ren'Py loads saves is super simple, I made a little snippet and I'd like to share it in case it might save anyone some time!

Basically you can put the following code in any `.rpy` file:
Code:
init python:
    import zipfile
    import pickle
    import cPickle

    def load_presave(name):
        raw = renpy.file(name)
        zip = zipfile.ZipFile(raw, "r")
        data = zip.read("log")
        zip.close()

        if renpy.config.use_cpickle:
            roots, log = cPickle.loads(data)
        else:
            roots, log = pickle.loads(data)
       
        log.unfreeze(roots, label="_after_load")
And you can call it anywhere, using the path to your save file relative to your `game/` directory:
Code:
label cutscene_prologue:
    scene bg black
   
    menu:
        "Skip to new content?"
        "Yes":
            $ load_presave("presaves/complete.save")
        "No":
            pass
The major win for me being that it even works on Android. I hope anyone has use for this, it's definitely nice for your players to include some presaves while your game is still in development!

Edit:
Just don't put the saves in the `save/` folder, Ren'Py is very specific about not including the `save/` folder in builds!