How do I force an autosafe in renpy at a specific point?

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,583
2,220
I never got this to work:

define config.autosave_on_choice = True
I'm not suggesting define can't be used this way... but I would expect config.autosave_on_choice to be in an init python: block.

If True, Ren'Py will autosave upon encountering an in-game choice. (When is called.)
Another option to consider is a single choice menu. No reason you need to give the player more than one choice.

Python:
init 2 python: #picking 2 just to be higher than the default of 0
    config.autosave_on_choice = True

label start:

    scene black with fade

    "*** START ***"

    menu:
        "Thank you for playing chapter 1"
        "Continue to chapter 2":
            pass

    "*** THE END ***"

    return
The "Contine to chapter 2" will appear as a single choice menu option... and I presume that clicking it, in combination with the config.autosave_on_choice = True will cause an autosave to happen.

Obviously you won't need the pass if you put some dialogue in there instead.

Ok, upgrade first.
Finally... You don't need to overwrite your existing RenPy SDK folder. You can have lots of them. Each one independent of another. As long as you rename your "Shortcut to RenPy.exe" to something like "RenPy 7.1.x" or whatever - you can pick whichever version you want to run at that given moment.

For a while last year, I think I was running 4 different versions just to avoid using "Build" and ending up with a different release that the original game was written in. A bit overkill and probably completely unnecessary, but I was err'ing on the side of caution. My point is that you don't need to "upgrade" - just use whichever release you want to use.

Edit: As an aside... Why are you trying to force an autosave anyway? The player can save or not save... their choice. It sounds like something that isn't really needed. I can't see the harm... but I can't see the point either. Nevermind, just read your original post.

With that in mind, I'll offer up the solution I ended up using to avoid changing chapter01 when chapter02 came out...
Edit2: Tweaked the code a bit, so it will continue to chapter 2 even if the player continues after saving during the "thanks for playing" screen.


Python:
# ----- script.rpy ----
label start:

    scene black with fade
    "*** START ***"
    jump ch01_start

label thank_you_for_playing:
    "Thanks for playing, blah, blah, Patreon, blah, blah, valuable players, blah, blah, next month...."
    return
Python:
# ----- chapter01.rpy ----
label ch01_start:

    # blah, blah.
    # lots of code, blah, blah.

    jump endof_ch01:

label endof_ch01:

    if not renpy.has_label("ch02_start")
        call thank_you_for_playing

    if renpy.has_label("ch02_start"):
        jump ch02_start
    else:
        return
I make sure I always start a new chapter with label chxx_start: and always end a chapter with that bit of code using if renpy.has_label().

If I've written chapter 02.... then chapter 01 just continues into chapter 02. If chapter 02 doesn't exist yet... then it calls the "Thanks for playing" in the primary script file, then continues. If chapter 02 still doesn't exist (kinda likely, given it didn't exist a second ago), it returns the main game menu.

However if the player saved during the "Thanks for playing" scene... then loads that same save AFTER chapter 02 is released and just continues clicking... it will actually go to chapter 02 instead of quitting.

In combination with the single choice menu and the autosave on menu choice... I think this would cover most circumstances.
 
Last edited:
  • Like
Reactions: Acehole_Studios

Porcus Dev

Engaged Member
Game Developer
Oct 12, 2017
2,582
4,692
I'm not sure where you want to save the file, but you could use this:
Python:
    $ FileTakeScreenshot()
    $ FileSave(1, confirm=False, page=1)()     ### Save in page 1, slot 1
Python:
    $ FileTakeScreenshot()
    $ FileSave(4, confirm=False, page=2)()     ### Save in page 2, slot 4
In this case you should alert players not to use certain pages as you will overwrite their save files if they are the ones you will use.

I also suppose there's a way to save those files in "automatic saves" or "quick saves"... In "quick saves" I didn't succeed, and in "automatic saves" I did, but Renpy overwrites them with its autosaves :ROFLMAO:
 
  • Like
Reactions: Acehole_Studios

the66

beware, the germans are cumming
Modder
Donor
Respected User
Jan 27, 2017
7,669
23,787
why using autosave at all? give the player the option to save.

Python:
label end:
    "bla"
    "bla"
    "The save menu will now be opend, save!"
    $ ShowMenu("save")()
 

the66

beware, the germans are cumming
Modder
Donor
Respected User
Jan 27, 2017
7,669
23,787
but if you really need something forced, w/o user interaction try this:
Python:
init python:
    def forced_save(name="forced-", slots=renpy.config.autosave_slots, extra_info="Forced Save"):
        renpy.loadsave.cycle_saves(name, slots)
        extra_info = extra_info
        renpy.exports.take_screenshot()
        renpy.loadsave.save("%s1" % name, extra_info=extra_info)
and in screens.rpy
Python:
screen navigation():
    .
    .
    .
    if main_menu and renpy.can_load("forced-1"):
        textbutton _("Continue Last Chapter") action FileLoad(1, "forced-")
    .
    .
    .
at the end of your chapter1.rpy use
Python:
label end_ch1:
    "bla"
    "bla"
    $ forced_save(extra_info="End of v%s" % config.version)
    if renpy.loadable("chapter2.rpyc"):
        jump start_ch2
    return
this is all for Ren'Py 7.3.4 and newer, i'm too lazy to check older versions.
 

recreation

pure evil!
Respected User
Game Developer
Jun 10, 2018
6,274
22,424
If I just use
renpy.force_autosave(True, True)
I get this from the start:
Code:
I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/episode3.rpy", line 585: expected statement.
    renpy.force_autosave(True, True)
                                    ^

Ren'Py Version: Ren'Py 7.1.1.929
Sat Jan 18 16:08:28 2020



If I use $renpy.force_autosave(True, True)
the game starts but crashs when it gets to the code

Code:
I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 115, in script call
    call episode3 from _call_episode3
  File "game/episode3.rpy", line 585, in script
    $renpy.force_autosave(True, True)
  File "game/episode3.rpy", line 585, in <module>
    $renpy.force_autosave(True, True)
TypeError: force_autosave() takes at most 1 argument (2 given)

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 115, in script call
    call episode3 from _call_episode3
  File "game/episode3.rpy", line 585, in script
    $renpy.force_autosave(True, True)
  File "D:\renpy\renpy-7.0.0-sdk\renpy\ast.py", line 882, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "D:\renpy\renpy-7.0.0-sdk\renpy\python.py", line 1913, in py_exec_bytecode
    exec bytecode in globals, locals
  File "game/episode3.rpy", line 585, in <module>
    $renpy.force_autosave(True, True)
TypeError: force_autosave() takes at most 1 argument (2 given)

Windows-8-6.2.9200
Ren'Py 7.1.1.929
Pink Prescriptions 0.2.1
Sat Jan 18 16:06:11 2020
I know this is old and probably fixed, but I was looking for something similar and seeing this $renpy.force_autosave(True, True) in the error code, there is the error: you simply missed the space between $ and renpy.force_autosave.

Sometimes it's the small things xD