Page 1 of 1

button "Continue game"

Posted: Sun Feb 18, 2018 8:55 am
by Andredron
1) plain(The code is outdated and does not work in new versions)

Code: Select all

# action - continue the game from there, where finished
# if there is nothing to upload yet, the button is inactive
# textbutton _ ("Continue game") action Continue ()
init -999 python
    class Continue (Action, DictEquality):
        def __call __ (self):
            FileLoad (1, confirm = False, page = "auto", newest = True) ()
        # clickable button
        def get_sensitive (self):
            return FileLoadable (1, page = "auto")

2) advanced
First, we'll make a record at the very beginning of script.rpy

Code: Select all

label main_menu:
    call screen main_menu
label restart:
    call screen confirm (message = u "Are you sure you want to restart the game?", yes_action = Start (), no_action = Jump ("main_menu"))
### Auto-save activation:
init -1 python hide:
    config.has_autosave = True
Next, we need to go into the script screen, and find there our main menu (I use the standard menu gui) and there add the selected fragments.

Code: Select all

screen navigation ():

    vbox:
        style_prefix "navigation"

        xpos gui.navigation_xpos
        yalign 0.5

        spacing gui.navigation_spacing

        if main_menu:

            textbutton _ ("Start Game") action Jump ("restart")

        else:

           textbutton _ ("History") action ShowMenu ("history")

           textbutton _ ("Save") action ShowMenu ("save")

        textbutton _ ("continue") action FileLoad (1, confirm = False, page = "auto", newest = True)
        textbutton _ ("Load game") action ShowMenu ("load")

        textbutton _ ("Options") action ShowMenu ("preferences")
What have we written down here:
When you click on the Start Game button, we call the restart label, which displays the notification screen message (confirm - on new, on old - yesno_prompt) in which you specify whether you want to start a new game.
And by clicking on the Continue game button, we automatically load the last auto save. Thanks to the fact that we registered the activation of autosave, we will load our last place where we stopped.

viewtopic.php?f=51&t=63397&p=547572&hil ... ad#p547572

Re: button "Continue game"

Posted: Sun Feb 18, 2018 3:38 pm
by Zetsubou
If you want a button that will continue from your last save of any variety (quick save, normal save, auto save) rather than just auto saves, you can use this instead:

Code: Select all

init +1 python:
    class LoadMostRecent(Action):

        def __init__(self):
            self.slot = renpy.newest_slot()

        def __call__(self):
            renpy.load(self.slot)

        def get_sensitive(self):
            return self.slot is not None
Then set the button's action to "LoadMostRecent()".

Re: button "Continue game"

Posted: Mon May 27, 2019 12:55 pm
by Ayael
Thank you both of you, it's very useful and simple !

Re: button "Continue game"

Posted: Sat Jun 15, 2019 4:37 pm
by Ayael
Zetsubou wrote:
Sun Feb 18, 2018 3:38 pm
If you want a button that will continue from your last save of any variety (quick save, normal save, auto save) rather than just auto saves, you can use this instead:

Code: Select all

init +1 python:
    class LoadMostRecent(Action):

        def __init__(self):
            self.slot = renpy.newest_slot()

        def __call__(self):
            renpy.load(self.slot)

        def get_sensitive(self):
            return self.slot is not None
Then set the button's action to "LoadMostRecent()".
This one is actually not working when there is no file (because we delete them all).
Finnaly, I used this :

Code: Select all

$lastsave=renpy.newest_slot(r"\d+")
if lastsave is not None:
    $ name, page = lastsave.split("-")
    textbutton _("Continue") action FileLoad(name, page)
Don't know if it takes everything though (auto/quick)

Found here : viewtopic.php?t=34420

Re: button "Continue game"

Posted: Sun Mar 22, 2020 8:03 pm
by badanni
you can use this

Code: Select all

if LoadMostRecent().get_sensitive():
.... action LoadMostRecent
to validate whether or not exist

Re: button "Continue game"

Posted: Fri Jan 07, 2022 11:49 pm
by lewishunter
Ayael wrote:
Sat Jun 15, 2019 4:37 pm

This one is actually not working when there is no file (because we delete them all).
Finnaly, I used this :

Code: Select all

$lastsave=renpy.newest_slot(r"\d+")
if lastsave is not None:
    $ name, page = lastsave.split("-")
    textbutton _("Continue") action FileLoad(name, page)
Don't know if it takes everything though (auto/quick)

Found here : viewtopic.php?t=34420
I think I fixed all the problems. It gets insensitive when the files are deleted and if you delete the newest file it will load the next newest one (including 'quick' and 'auto', but not '_reload'). It's what Pytom did but in action form (easier to write and mantain)

Code: Select all

init -999 python:

    def newest_slot_tuple():
        """
        Returns a tuple with the newest slot page and name.
        """
        newest = renpy.newest_slot()

        if newest is not None:
            page, name = newest.split("-")
            return (page, name)


    class Continue(Action):
        """
        Loads the last save file.
        """

        def __call__(self):

            if not self.get_sensitive():
                return

            # Assign variables from the tuple.
            newest_page, newest_name = newest_slot_tuple()

            # Load the file using the newest slot information.
            FileLoad(newest_name, confirm=False, page=newest_page, newest=True)()

        def get_sensitive(self):

            # Insensitive in-game.
            if not main_menu:
                return False

            # Insensitive during replay mode.
            if _in_replay:
                return False

            # Get the tuple.
            newest = newest_slot_tuple()

            # Insensitive if no new slot files.
            if newest is None:
                return False

            # Assign variables from the tuple.
            newest_page, newest_name = newest

            # Insensitive if the newest save is '_reload-*'
            if newest_page == '_reload':
                return False
                
            # This action returns true if the file is loadable.
            return FileLoadable(newest_name, page=newest_page)
Use it like this:

Code: Select all

textbutton "Continue" action Continue()

Re: button "Continue game"

Posted: Tue Feb 15, 2022 6:29 pm
by Ayael
Thanks!