[SOLVED] Altered Save System and FileScreenshot() issue.

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
thexerox123
Regular
Posts: 134
Joined: Fri Jan 20, 2023 3:21 pm
itch: thexerox123
Contact:

[SOLVED] Altered Save System and FileScreenshot() issue.

#1 Post by thexerox123 »

I've set up a system that has 4 selectable player profiles, and as a result, I've had to change how a lot of my save/load systems work.

(The profile system is largely detailed here... I want to post it to the Cookbook subforum once I have some issues like this one ironed out.)

I'm also using a system that I found to continue from last save, with some additions:

Continue.rpy:

Code: Select all

init -999 python:

    def newest_slot_tuple():
        """
        Returns a tuple with the newest slot page and name.
        """
        if profile_id == 1:
            newest = renpy.newest_slot('1')
        if profile_id == 2:
            newest = renpy.newest_slot('2')
        if profile_id == 3:
            newest = renpy.newest_slot('3')
        if profile_id == 4:
            newest = renpy.newest_slot('4')

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

    def forcesave():
        renpy.take_screenshot()
        if profile_id == 1:
            renpy.save("1-1", save_name)
        if profile_id == 2:
            renpy.save("2-100", save_name)
        if profile_id == 3:
            renpy.save("3-199", save_name)
        if profile_id == 4:
            renpy.save("4-298", save_name)
        return


    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)
I made some changes to the save and load screens, the most important being that I siloed the save files slots into different profiles, so that each profile button handles and displays only its own save files.

screens.rpy:

Code: Select all

                        for i in range(gui.file_slot_cols * gui.file_slot_rows):
                            if profile_id == 2:
                                $ slot_adjust = 99
                            elif profile_id == 3:
                                $ slot_adjust = 198
                            elif profile_id == 4:
                                $ slot_adjust = 297
                            else:
                                $ slot_adjust = 0     
Because of this, I disabled autosave and quicksave rather than figure out how to get them working with regexp.

Now, I recently added a vbox to my profile buttons to show the filescreenshot of the most recent save, and also wanted to set up a pseudo autosave system, so that the player can't start a profile but not have a save file. Hence the forcesave() function that I added to Continue.rpy. The first slot in each save file group is the designated autosave slot.

Here's an example of the button logic:

Code: Select all

screen playprofiles:
    vbox:
        imagebutton:
            idle "images/interacts/GreenBox.png"
            hover Transform("images/interacts/GreenBox.png", matrixcolor=TintMatrix("#66ff3d"))
            xpos 320 ypos 270
            action [SetVariable("profile_id", 1),FilePage(1),Jump("first")]
    if persistent.profile1 == True:
        vbox:
            text "[persistent.player_name_1]" color "#FFF"
            xalign 0.33 yalign 0.31
        vbox:
            text FileSaveName(renpy.newest_slot('1'), slot = True, page = True) color "#FFF" size 20
            xalign 0.33 yalign 0.36
        vbox:
            image FileScreenshot(renpy.newest_slot('1'), slot = True, page = True)
            xalign 0.32 yalign 0.46
            at zoomless
Now, here's the issue... the FileScreenshot function works well for the saves, and on the profile screen, it then shows the correct image... but, if I then use the Continue from Last Save function in that profile, it loads from the correct place, but seems to take a screenshot of the continue menu that replaces that most recent image on the save.

Image

Is there a conditional that I could add to my forcesave() function that would only activate the filescreenshot on save but not on load? Or to have it load to just after the point where it initiates the save?
Last edited by thexerox123 on Mon Apr 03, 2023 6:11 pm, edited 1 time in total.

User avatar
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Altered Save System and FileScreenshot() issue.

#2 Post by _ticlock_ »

thexerox123 wrote: Mon Apr 03, 2023 2:39 pm Is there a conditional that I could add to my forcesave() function that would only activate the filescreenshot on save but not on load? Or to have it load to just after the point where it initiates the save?
I believe you use $ forcesave() directly as RenPy statement.
You should do something similar to what force_autosave function does. Check force_autosave definition.

For example:

Code: Select all

    def forcesave():
        # Do not save if in rollback mode
        if renpy.game.after_rollback or renpy.exports.in_rollback():
            return

        # Do not save if we're in the main menu.
        if renpy.store.main_menu:
            return

        # Do not save if we're in a replay.
        if renpy.store._in_replay:
            return
            
        renpy.take_screenshot()
            
        renpy.save("1-1", save_name)

thexerox123
Regular
Posts: 134
Joined: Fri Jan 20, 2023 3:21 pm
itch: thexerox123
Contact:

Re: Altered Save System and FileScreenshot() issue.

#3 Post by thexerox123 »

_ticlock_ wrote: Mon Apr 03, 2023 4:31 pm I believe you use $ forcesave() directly as RenPy statement.
You should do something similar to what force_autosave function does. Check force_autosave definition.

For example:

Code: Select all

    def forcesave():
        # Do not save if in rollback mode
        if renpy.game.after_rollback or renpy.exports.in_rollback():
            return

        # Do not save if we're in the main menu.
        if renpy.store.main_menu:
            return

        # Do not save if we're in a replay.
        if renpy.store._in_replay:
            return
            
        renpy.take_screenshot()
            
        renpy.save("1-1", save_name)
Ahhh, thank you once again, _ticlock_! That did the trick.

I added:

Code: Select all

screen playprofiles:
    on "show" action SetVariable("profiletog", True)
    on "hide" action SetVariable("profiletog", False)
And added those to my forcesave function:

Code: Select all

    def forcesave():
                # Do not save if in rollback mode
        if renpy.game.after_rollback or renpy.exports.in_rollback():
            return

        # Do not save if we're in the main menu.
        if renpy.store.main_menu:
            return

        # Do not save if we're in a replay.
        if renpy.store._in_replay:
            return

        if profiletog == True:
            return
            
        renpy.take_screenshot()
        if profile_id == 1:
            renpy.save("1-1", save_name)
        if profile_id == 2:
            renpy.save("2-100", save_name)
        if profile_id == 3:
            renpy.save("3-199", save_name)
        if profile_id == 4:
            renpy.save("4-298", save_name)
        return
(Added the example ones just in case, as I don't want it saving in those instances, even though they probably wouldn't come up.)

Worked like a charm, thank you! I hadn't thought to look at autosave as an example, since I had ruled out using them.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot], mivvy