Making a "Lock Save" action

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
User avatar
GreyWolfXx
Regular
Posts: 68
Joined: Fri Jun 05, 2015 1:00 am
IRC Nick: Grey
Skype: GreyWolfXxII
Contact:

Making a "Lock Save" action

#1 Post by GreyWolfXx »

How could I make an action in the Load/Save menu so that players could lock a game state? Meaning that they can't delete it or overwrite these locked saves.

"We have been to the moon, we have charted the depths of the ocean and the heart of the atom,
but we have a fear of looking inward to ourselves because we sense that is where
all the contradictions flow together." -- Terrence Mckenna

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Making a "Lock Save" action

#2 Post by PyTom »

We can't do this - but it's a good idea. I'll look at what it will take to add something like this.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
GreyWolfXx
Regular
Posts: 68
Joined: Fri Jun 05, 2015 1:00 am
IRC Nick: Grey
Skype: GreyWolfXxII
Contact:

Re: Making a "Lock Save" action

#3 Post by GreyWolfXx »

Oh really? Alright, thank you!

"We have been to the moon, we have charted the depths of the ocean and the heart of the atom,
but we have a fear of looking inward to ourselves because we sense that is where
all the contradictions flow together." -- Terrence Mckenna

User avatar
15nick
Regular
Posts: 33
Joined: Thu Oct 17, 2013 2:46 am
Contact:

Re: Making a "Lock Save" action

#4 Post by 15nick »

I did something like that with a persistent list variable (persistent.locked). I had an imagebutton that called one of two functions based on whether the save was locked or unlocked (unlockSave or lockSave) that either appended or removed the filename to persistent.locked. Then under the button actions for the save screen I had an if statement that would check to see if the filename was in persistent.locked. If it was, I'd have the action be nothing. Otherwise it'd do the FileSave() action. I actually have it a lot more complicated than that because I tried adding a bunch of additional features and also use an imagemap, but just for locking a save that seemed to work.

So in options.rpy I had:

Code: Select all

init -1 python hide:

    if persistent.locked is None:
        persistent.locked = []
the functions were thrown in a specific file I had for definitions, but it could be in any file I believe:

Code: Select all

init python:
            
    def lockSave(slotname):
        persistent.locked.append(slotname)
        if persistent.locked is None:
            persistent.locked = []
        
    def unlockSave(slotname):
        persistent.locked.remove(slotname)
        if persistent.locked is None:
            persistent.locked = []
(the "if persistent.locked is None: persistent.locked = []" parts for the functions were just because it was throwing weird errors and that seemed to fix it, your code may work without it)

Since the game I have locked saves for uses imagemap and the button code I'm getting from another game doesn't have locked saves, my code is much different than the default save/load code. So you might need to mess around with it for it to work, but maybe try

Code: Select all

screen file_picker():

    frame:
        style "file_picker_frame"

        has vbox

        # The buttons at the top allow the user to pick a
        # page of files.
        hbox:
            style_group "file_picker_nav"

            textbutton _("Previous"):
                action FilePagePrevious()

            textbutton _("Auto"):
                action FilePage("auto")

            textbutton _("Quick"):
                action FilePage("quick")

            for i in range(1, 9):
                textbutton str(i):
                    action FilePage(i)

            textbutton _("Next"):
                action FilePageNext()

        $ columns = 2
        $ rows = 5

        # Display a grid of file slots.
        grid columns rows:
            transpose True
            xfill True
            style_group "file_picker"

            # Display ten file slots, numbered 1 - 10.
            for i in range(1, columns * rows + 1):

                # Each file slot is a button.
                button:
                    $ file_name = FileSlotName(i, columns * rows)
                    $ file_time = FileTime(i, empty=_("Empty Slot."))
                    $ save_name = FileSaveName(i)
                    if(file_name in persistent.locked):
                        action None
                    else:
                        action FileAction(i)
                    xfill True

                    has hbox

                    # Add the screenshot.
                    add FileScreenshot(i)

                    text "[file_name]. [file_time!t]\n[save_name!t]"

                    if(file_name in persistent.locked):
                        if file_time != "Empty Slot.":
                            imagebutton:
                                idle "lock_close.png"
                                hover "lock_open.png"
                                action [Function(unlockSave, file_name)]
                    else:
                        if file_time != "Empty Slot":
                            imagebutton:
                                idle "lock_open.png"
                                hover "lock_close.png"
                                action [Function(lockSave, file_name)]

                    if(file_name not in persistent.locked):
                        key "K_DELETE" action [FileDelete(i)]
in whatever file you have the save/load screen code. Like I said, I kind of had to piece the two together so some of the code might be wrong. But that's the general gist of what I did to get locked saves to work for my game.

And here's what it looks like on mine*:
Save is unlocked and delete icon is clickable
Save is unlocked and delete icon is clickable
and
Save is locked and delete icon unclickable
Save is locked and delete icon unclickable
*Trashcan code not included

edit: also you might want to add a little blurb so it only makes the save button have no action when locked if it's on the save screen. Otherwise no one can load their locked saves. My code has the load and save screens as separate so I didn't have to figure out how to differentiate between the two, so I don't know how to help there.

User avatar
GreyWolfXx
Regular
Posts: 68
Joined: Fri Jun 05, 2015 1:00 am
IRC Nick: Grey
Skype: GreyWolfXxII
Contact:

Re: Making a "Lock Save" action

#5 Post by GreyWolfXx »

Thanks, 15nick, this is really helpful! I think I'll be able to do it now :D. I'll post any further questions here.

"We have been to the moon, we have charted the depths of the ocean and the heart of the atom,
but we have a fear of looking inward to ourselves because we sense that is where
all the contradictions flow together." -- Terrence Mckenna

Post Reply

Who is online

Users browsing this forum: barsunduk, dragondatingsim, Majestic-12 [Bot]