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.

3) Use [`action Continue()`](https://www.renpy.org/doc/html/screen_a ... l#Continue) added since version 8.1.1

Something like this:

Code: Select all

screen navigation():
    
    vbox:

        if main_menu:

            if renpy.newest_slot != None:

                textbutton _("Continue") action Continue()

            else:

                textbutton _("New game") action Start()
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!

Re: button "Continue game"

Posted: Fri Aug 04, 2023 8:54 am
by Andredron

Code: Select all

init python: #This will be done as soon as the game is open
    #useful imports
    import os                       
    from datetime import datetime
    import pickle

    #makes last_open_date a global variable that can be accessed everywhere, so you can use it whenever you need it. 
    #If last_open_date is None, it means that this is the first time the game has been open
    last_open_date = None

    #checks if the file exists. The file will not exist the first time you open the game
    #as written here, this will save the file on the same folder as the game saves, on windows that is %appdata%/renpy/nameOfMod. You can change this to your liking of course
    if os.path.exists(os.path.join(config.savedir, "time")):
        #this opens the file so it can be read, in binary form. We read and write to the file in binary because while not impossible, it's much harder for someone to tamper with the file
        with open("time", "br") as file:
            #this loads the date from the file
            last_open_date = pickle.load(file)
            #This closes the file
            file.close()

    #At this point, last_open_date is either None, which means this is the first time the game is opened, or it contains the time the game was opened last.
    #You can now do any operation you desire on it


label on_close: #this is the label you should call as you exit the game

    python:
        #gets the date of the computer at this moment, down to the microsecond, but I'm guessing you don't need that much precision :)
        current_date = datetime.now()
        #opens the file for writing in binary
        with open(os.path.join(config.savedir, "time"), "wb") as file:
            #dumps the entire date object into the file. This way, we don't have to worry about formatting, python handles that for us
            pickle.dump(current_date, file)
            #closes the file
            file.close()

        #quits the game
        renpy.quit()

Re: button "Continue game"

Posted: Sat Aug 05, 2023 3:18 am
by Imperf3kt
I just use this

Code: Select all

screen main_menu():



    ## This ensures that any other menu screen is replaced.
    tag menu

    ## This is used by the "Continue" function, to load the most recent save.
    $recent_save = renpy.newest_slot(r"\d+")
    
    vbox:
        if recent_save:
            $ recent_save_page, recent_save_name = recent_save.split("-")
            textbutton _("Continue") action FileLoad(recent_save_name, confirm=True, page=recent_save_page)
Works great here for years, no issues so far.
Style it how you need.

Re: button "Continue game"

Posted: Mon Aug 07, 2023 1:38 am
by Another_Tom
Imperf3kt wrote: Sat Aug 05, 2023 3:18 am I just use this
This works like a charm, but I don't understand why the text button is constantly highlighted.

I just want to show this button in the main_menu like any other button:

Code: Select all

if main_menu:

            $ recent_save=renpy.newest_slot(r"\d+")
            if recent_save:
                $ recent_save_page, recent_save_name = recent_save.split("-")
                textbutton _("Continue Game") action FileLoad(recent_save_name, confirm=True, page=recent_save_page)
            
            textbutton _("Start new Game") action Start()

        ...
Edit: I got it, It's because of "Confirm=True" changed it to "Confirm=False" and it works.

Re: button "Continue game"

Posted: Fri Feb 16, 2024 1:55 pm
by Seraphimist
Another_Tom wrote: Mon Aug 07, 2023 1:38 am
Imperf3kt wrote: Sat Aug 05, 2023 3:18 am I just use this
I don't understand why the text button is constantly highlighted.
I was having this problem too. It turns out, FileLoad sets the button as selected if newest=True, which it is by default. FileLoad is usually used for loading a file from a Load Game screen. I guess it would normally highlight the thumbnail from the most recent game.

To fix, I used Continue() instead of FileLoad

Code: Select all

$recent_save = renpy.newest_slot(r"\d+")
if recent_save:
    textbutton _("Continue") action Continue(regexp=r"\d+", confirm=True)

https://www.renpy.org/doc/html/screen_a ... l#Continue
https://www.renpy.org/doc/html/screen_a ... l#FileLoad

Re: button "Continue game"

Posted: Sun Feb 18, 2024 7:13 am
by Another_Tom
Seraphimist wrote: Fri Feb 16, 2024 1:55 pm
Another_Tom wrote: Mon Aug 07, 2023 1:38 am
Imperf3kt wrote: Sat Aug 05, 2023 3:18 am I just use this
I don't understand why the text button is constantly highlighted.
I was having this problem too. It turns out, FileLoad sets the button as selected if newest=True, which it is by default. FileLoad is usually used for loading a file from a Load Game screen. I guess it would normally highlight the thumbnail from the most recent game.

To fix, I used Continue() instead of FileLoad

Code: Select all

$recent_save = renpy.newest_slot(r"\d+")
if recent_save:
    textbutton _("Continue") action Continue(regexp=r"\d+", confirm=True)

https://www.renpy.org/doc/html/screen_a ... l#Continue
https://www.renpy.org/doc/html/screen_a ... l#FileLoad
I'm still using Imperf3kt's snippet and all I had to do was to set the "confirm" to False

Code: Select all

textbutton _("Continue") action FileLoad(recent_save_name, confirm=False, page=recent_save_page)

Re: button "Continue game"

Posted: Thu May 30, 2024 12:08 pm
by Andredron
Use [`action Continue()`](https://www.renpy.org/doc/html/screen_a ... l#Continue) added since version 8.1.1

Something like this:

Code: Select all


screen navigation():
    
    vbox:

        if main_menu:

            if renpy.newest_slot != None:

                textbutton _("Continue") action Continue()

            else:

                textbutton _("New game") action Start()