Continue button

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
Neyunse
Newbie
Posts: 8
Joined: Fri Aug 17, 2018 7:08 pm
Projects: Roses Of Love
Organization: KagariSoft
Github: Neyunse
itch: KagariSoft
Location: Argentina
Contact:

Continue button

#1 Post by Neyunse »

Well this code is based on this old publication...(viewtopic.php?t=48154) And I thought you might be interested in this updated code.

Code: Select all

init +1 python:
    def Can_load():
        lastsave=renpy.newest_slot() # get the newest slot
        CanLoad = renpy.can_load(lastsave, test=False) # check if it can be loaded
        print(lastsave)

        if lastsave is not None: # prevent crash if '_reload-*' not exist in saves
            if '_reload' in lastsave:
                return False # if '_reload' in saves, return False.
            else:
                if CanLoad:
                    return CanLoad # Return True if the save can be loaded.
                else:
                    return CanLoad # Return False if the save cannot be loaded.
        else:
            return False
        
    
    def Load_NewSave():
        lastsave=renpy.newest_slot() # Get the newest save slot.
        renpy.load(lastsave) # The load the save.
 
screen ContinueButton():
    if Can_load():
        textbutton _("Continue") action Function(Load_NewSave)
     
screen navigation():
    use ContinueButton()
    # ...
 
----------------------------------------------------
My Twitter: @Neyunse
My Discord: ねゆんせ#7916
----------------------------------------------------
KagariSoft Twitter: @KagariSoft
My Discord Server

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

Re: Continue button

#2 Post by lewishunter »

I think I found a way to make It simpler. This way It becomes an action following Ren'Py guidelines.

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)
Then just use the action:

Code: Select all

textbutton "Continue" action Continue()

Post Reply

Who is online

Users browsing this forum: Bing [Bot]