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: 535
Joined: Thu Dec 28, 2017 2:37 pm
Completed: Kimi ga nozomu renpy-port(demo), Albatross Koukairoku(demo)
Projects: Sisters ~Natsu no Saigo no Hi~(renpy-port)
Location: Russia
Contact:

button "Continue game"

#1 Post by Andredron » Sun Feb 18, 2018 8:55 am

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
Last edited by Andredron on Wed Sep 07, 2022 5:22 am, edited 2 times in total.
I'm writing a Renpy textbook (in Russian). https://disk.yandex.ru/i/httNEajU7iFWHA (all information is out of date) Update 22.06.18

Help me to register in QQ International

Honest Critique

User avatar
Zetsubou
Miko-Class Veteran
Posts: 513
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 » 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()".
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
-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

Image

User avatar
Ayael
Regular
Posts: 81
Joined: Fri Apr 07, 2017 2:17 pm
Projects: Anoldor, medieval fantasy otome game.
Contact:

Re: button "Continue game"

#3 Post by Ayael » Mon May 27, 2019 12:55 pm

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

User avatar
Ayael
Regular
Posts: 81
Joined: Fri Apr 07, 2017 2:17 pm
Projects: Anoldor, medieval fantasy otome game.
Contact:

Re: button "Continue game"

#4 Post by Ayael » Sat Jun 15, 2019 4:37 pm

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

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 » Sun Mar 22, 2020 8:03 pm

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 » Fri Jan 07, 2022 11:49 pm

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()

User avatar
Ayael
Regular
Posts: 81
Joined: Fri Apr 07, 2017 2:17 pm
Projects: Anoldor, medieval fantasy otome game.
Contact:

Re: button "Continue game"

#7 Post by Ayael » Tue Feb 15, 2022 6:29 pm

Thanks!

Post Reply

Who is online

Users browsing this forum: No registered users