button "Continue game"

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
User avatar
Andredron
Miko-Class Veteran
Posts: 784
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

button "Continue game"

#1 Post 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
Last edited by Andredron on Thu May 30, 2024 12:18 pm, edited 4 times in total.
Renpy textbook (in Russian). https://disk.yandex.ru/i/httNEajU7iFWHA (all information is out of date) Update 22.06.18

Sawa - a game of the Drow Nation

Honest Critique

Poses in visual novels, or how to hold a character properly in the frame

Help save articles to the webarchive. [/color]

Please save your projects on github, you would know how hard it is to find projects after 7 years...

User avatar
Zetsubou
Miko-Class Veteran
Posts: 523
Joined: Wed Mar 05, 2014 1:00 am
Completed: See my signature
Github: koroshiya
itch: zetsuboushita
Contact:

Re: button "Continue game"

#2 Post 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()".
Finished games
-My games: Sickness, Wander No More, Max Massacre, Humanity Must Perish, Tomboys Need Love Too, Sable's Grimoire, My Heart Grows Fonder, Man And Elf, A Dragon's Treasure, An Adventurer's Gallantry
-Commissions: No One But You, Written In The Sky, Diamond Rose, To Libertad, Catch Canvas, Love Ribbon, Happy Campers, Wolf Tails

Working on:
Sable's Grimoire 2

https://zetsubou.games

Ayael
Regular
Posts: 82
Joined: Fri Apr 07, 2017 2:17 pm
Projects: Imperial Grace (on going), Autumn Spirit, Ballads at Midnight
Contact:

Re: button "Continue game"

#3 Post by Ayael »

Thank you both of you, it's very useful and simple !
Image Image

Ayael
Regular
Posts: 82
Joined: Fri Apr 07, 2017 2:17 pm
Projects: Imperial Grace (on going), Autumn Spirit, Ballads at Midnight
Contact:

Re: button "Continue game"

#4 Post 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
Image Image

User avatar
badanni
Newbie
Posts: 9
Joined: Fri Jan 24, 2020 11:57 am
itch: badanni
Location: Quito, Ecuador
Contact:

Re: button "Continue game"

#5 Post by badanni »

you can use this

Code: Select all

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

lewishunter
Newbie
Posts: 13
Joined: Sun Aug 01, 2021 8:06 pm
Contact:

Re: button "Continue game"

#6 Post 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()

Ayael
Regular
Posts: 82
Joined: Fri Apr 07, 2017 2:17 pm
Projects: Imperial Grace (on going), Autumn Spirit, Ballads at Midnight
Contact:

Re: button "Continue game"

#7 Post by Ayael »

Thanks!
Image Image

User avatar
Andredron
Miko-Class Veteran
Posts: 784
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

Re: button "Continue game"

#8 Post 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()
Renpy textbook (in Russian). https://disk.yandex.ru/i/httNEajU7iFWHA (all information is out of date) Update 22.06.18

Sawa - a game of the Drow Nation

Honest Critique

Poses in visual novels, or how to hold a character properly in the frame

Help save articles to the webarchive. [/color]

Please save your projects on github, you would know how hard it is to find projects after 7 years...

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3828
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: button "Continue game"

#9 Post 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.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

Another_Tom
Regular
Posts: 67
Joined: Mon Apr 24, 2023 9:06 am
Completed: Harold And The Witches
Projects: Steven On The Run
itch: dantom
Location: Germany
Contact:

Re: button "Continue game"

#10 Post 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.

Seraphimist
Newbie
Posts: 1
Joined: Fri Feb 16, 2024 1:48 pm
Contact:

Re: button "Continue game"

#11 Post 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

Another_Tom
Regular
Posts: 67
Joined: Mon Apr 24, 2023 9:06 am
Completed: Harold And The Witches
Projects: Steven On The Run
itch: dantom
Location: Germany
Contact:

Re: button "Continue game"

#12 Post 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)

User avatar
Andredron
Miko-Class Veteran
Posts: 784
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

Re: button "Continue game"

#13 Post 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()
Renpy textbook (in Russian). https://disk.yandex.ru/i/httNEajU7iFWHA (all information is out of date) Update 22.06.18

Sawa - a game of the Drow Nation

Honest Critique

Poses in visual novels, or how to hold a character properly in the frame

Help save articles to the webarchive. [/color]

Please save your projects on github, you would know how hard it is to find projects after 7 years...

Neyunse
Newbie
Posts: 9
Joined: Fri Aug 17, 2018 7:08 pm
Projects: Roses Of Love
Organization: KagariSoft
Github: Neyunse
itch: KagariSoft
Location: Argentina
Contact:

Re: button "Continue game"

#14 Post by Neyunse »

I recommend this option

Code: Select all

screen main_menu_buttons:
    
    if Continue(r"(?!_reload).+").get_sensitive():
        textbutton _("Continue") action Continue(r"(?!_reload).+") 
    else:
    	textbutton _("Play") action Start()
----------------------------------------------------
My Twitter: @Neyunse
My Discord: ねゆんせ#7916
----------------------------------------------------
KagariSoft Twitter: @KagariSoft
My Discord Server

Post Reply

Who is online

Users browsing this forum: No registered users