Naming savegames

dacris69

M, TI
Donor
Nov 20, 2017
2,111
6,017
Anyone can explain what to do in order to name the saves when saving in renpy games? If its not to complicated :LOL:
 

wurg

Active Member
Modder
Apr 19, 2018
705
1,629
Anyone can explain what to do in order to name the saves when saving in renpy games? If its not to complicated :LOL:
I tried to look this up for you but I don't know where in the Renpy to see the save game code. The best I can up with is this page: . 'save_name = ' is what is used to name the save, as far as I can tell, but I don't know where to put it.

If you know what part of the RenPy code deals with save you can look at the game Dating my Daughter's code, I know that game allows you to name a save, and copy it. Maybe someone like @Rich could help, after all he is a coding god.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,130
14,809
The best I can up with is this page: . 'save_name = ' is what is used to name the save, as far as I can tell, but I don't know where to put it.
I don't think it's what he talk about. save_name is for the physical name of the file, while OP probably think more of the logical name like in DmD.


If you know what part of the RenPy code deals with save you can look at the game Dating my Daughter's code, I know that game allows you to name a save, and copy it.
It's probably in "screens.rpy", file_slots screen.
Anyway it's a hack, not something that Ren'py can do by itself. As far as I understood it (never really cared yet), they one field of the save file to store a string that will be used as logical name.
 

wurg

Active Member
Modder
Apr 19, 2018
705
1,629
After what @anne O'nymous said I looked up two games and found some code in those games that deal with naming a save game, I don't know if this is all the code or not, you'll need someone smarter than me in Renpy and python to know this, but this should give you an idea, both are in the screens.rpy file:

Dreams of Desire the lost memories:

You don't have permission to view the spoiler content. Log in or register now.


Dating my Daughter:

You don't have permission to view the spoiler content. Log in or register now.

There could be more than this, I don't know for sure, but this is what I found.
 
  • Like
Reactions: anne O'nymous

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,130
14,809
Code:
init python:
    def name_func(newstring):
        store.save_name = newstring
Alright, so it was my "I am an idiot" day. You were right, "save_name" is what he was looking for. The documentation say about it that it's "one variable that is used by the high-level save system", and that's all my brain stored, making me wrongly remember it as the physical name.
So in the end the answer is way more easy. @dacris69 just need to assign a value to "save_name", either by himself to display some stats, like in DmD, or by asking to the player, like in DoD.

Side note regarding the second option:
It's really annoying for the player to always have to enter a name every time he save. It's not necessarily visible for the dev, because he don't save this often his own game, but for a player it can quickly become a pain in the ass.
I mean, the implication of this or that choice aren't always obvious. So you save, just in case. Then three dialogs lines later come another choice, and another save... And all this three, four or even more time, in less than two minutes. With each time the need to gave a name to the save...
So, it would be a really good idea to make this naming optional, or something like this. If you want, you can take a look at @veqvil 's and how he achieved to have a not too invasive way to name the save files.
 
  • Like
Reactions: Rich

OhWee

Forum Fanatic
Modder
Game Developer
Jun 17, 2017
5,660
28,491
I'm necro-ing this thread instead of starting a new one.

Here's how I've been doing this (Note: see FmF for an implemented example of this in action):

---

I marked the relevant bits with comments, mainly just skip down to:

action If(renpy.get_screen("save"), true=Show("save_name_modal", accept=FileSave(i)), false=FileLoad(i))

Then look for this to display the value once it's been set:

Code:
                        hbox:

                            area (15, -15, 300, 140)
                            text FileSaveName(slot):
                                style "slot_name_text"
                                size 21
                                yalign 0.5
And, for the popup window that asks for a save name descrption, see all of the code inside of this screen (near the bottom below the style declarations).

screen save_name_modal(accept=NullAction()):

Below is the full snippet of code from screens.rpy that I'm using for the file_slots screen.

Code:
screen file_slots(title):

    default page_name_value = FilePageNameInputValue(pattern=_("Page {}"), auto=_("Automatic saves"), quick=_("Quick saves"))

    use game_menu(title):

        fixed:

            ## This ensures the input will get the enter event before any of the
            ## buttons do.
            order_reverse True

            ## The page name, which can be edited by clicking on a button.
            button:
                style "page_label"

                key_events True
                xalign 0.995
                xoffset 60
                yalign 0.025
                action page_name_value.Toggle()

                input:
                    style "page_label_text"
                    value page_name_value

            ## The grid of file slots.
            grid 5 2:
                style_prefix "slot"

                xalign 0.5
                yalign 0.375

                spacing 12

                for i in range(1, 11):

                    $ slot = i

                    button:

                        # the line below is the relevant code for adding a save description.
                            # it Replaces action FileAction(slot)

                        action If(renpy.get_screen("save"), true=Show("save_name_modal", accept=FileSave(i)), false=FileLoad(i))

                        has vbox

                        $ file_name = FileSlotName(i, 11)
                        $ file_time = FileTime(i, empty=_("Empty Slot."))
                        $ save_name = FileSaveName(i)

                        text FileTime(slot, format=_("{#file_time}%A, %B %d %Y, %H:%M"), empty=_("empty slot")):
                            style "slot_time_text"
                            xalign 0.5
                            yoffset 2
                            xoffset 24

                        add FileScreenshot(slot) xoffset 24 yoffset 11

                        # I like to have delete buttons on my load/save pages, for those people that might be using a touchscreen.  As usual, you can also delete by hovering over the save slot and hitting the 'del' key.  This 'if' check to see if the file slot is not empty, and if so, adds a delete button, which I've manually positioned.  Ignore the next two lines if you have no need for having delete buttons on your save screen.

                        if FileTime(slot) != "":      

                            imagebutton auto "gui/button/sv_delete_%s.png" action FileDelete(i) xpos 163 ypos 175

                       # And here is where the text you enter in the save game description popup is displayed.  I've included the File Save Name in it's own hbox, so that I can control the positioning and width of the text entry.  I placed this last inside of the button so that it wouldn't mess up the other alignments, but I just changed it to area so that may or may not have have fixed that issue...

                        hbox:

                            area (15, -15, 300, 140)
                            text FileSaveName(slot):
                                style "slot_name_text"
                                size 21
                                yalign 0.5




                        key "save_delete" action FileDelete(slot)

            ## Buttons to access other pages.
            hbox:
                style_prefix "page"

                xalign 0.5
                yalign 0.025

                spacing gui.page_spacing

                textbutton _("<") action FilePagePrevious()

                if config.has_autosave:
                    textbutton _("{#auto_page}A") action FilePage("auto")

                if config.has_quicksave:
                    textbutton _("{#quick_page}Q") action FilePage("quick")

                ## range(1, 10) gives the numbers from 1 to 9.
                for page in range(1, 10):
                    textbutton "[page]" action FilePage(page)

                textbutton _(">") action FilePageNext()

style page_label is gui_label
style page_label_text is gui_label_text
style page_button is gui_button
style page_button_text is gui_button_text

style slot_button is gui_button
style slot_button_text is gui_button_text
style slot_time_text is slot_button_text
style slot_name_text is slot_button_text

style page_label:
    xpadding 75
    ypadding 5

style page_label_text:
    text_align 0.5
    layout "subtitle"
    hover_color gui.hover_color

style page_button:
    properties gui.button_properties("page_button")

style page_button_text:
    properties gui.button_text_properties("page_button")

style slot_button:
    properties gui.button_properties("slot_button")

style slot_button_text:
    properties gui.button_text_properties("slot_button")

# And here is the screen that pops up asking to name your save:

screen save_name_modal(accept=NullAction()):
    modal True
    add Solid("#8f72f2") alpha 0.8
    style_prefix "save_name_modal"

    frame:
        xpadding 6
        ypadding 6
        has vbox:
            xalign 0.5
            spacing 20

        label _("Please name your save: \n     Max 120 characters"):
            text_color "#09f"
            xalign 0.5

        null height 10

        input size 40 color "#09f" default store.save_name changed set_save_name length 120 allow "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789?!,. -/*":
            yalign 1.0
            xalign 0.5
            xysize (550, 40)

        textbutton _("Save game"):
            xalign 0.5
            action [accept, Hide("save_name_modal")]

        key "game_menu" action Hide("save_name_modal")

The layout using the above code looks something like this in my current project that I'm piddling away at atm. Your layout and grid pattern/tile count will likely be different of course, and the Renpy menu is usually at the left, not the bottom unless someone (like me) decides to relocate it...

(Attachment issues atm, previous screenshot, will update screenshots later with the popup screen shown as well as this screen):


------

I have essentially the same code implemented in FmF, although the layout and grid size is layed out differently 'cuz I roll that way...

Anyways, the main reason why I'm bumping this thread is that I've tried a few ways unsuccessfully to add a function to edit theFileSaveName(slot) variable after it is initially set, so that people can re-name their saves later if they feel the need.

Making the edit button is easy enough (see delete button), but I cant figure out how to change the value of FileSaveName(slot) once it's been set during the save function. Does anyone have any ideas on how to edit this variable once it's been set?
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,130
14,809
And, for the popup window that asks for a save name descrption,
Nowadays games mostly rely on a less intrusive, and therefore less annoying, approach than a popup window:
Python:
screen file_slots(title):

    default page_name_value = FilePageNameInputValue(pattern=_("Page {}"), auto=_("Automatic saves"), quick=_("Quick saves"))

    use game_menu(title):

        fixed:
[...]
                input:
                    style "page_label_text"
                    value page_name_value

            # <----
            if title == "Save":
                hbox:
                    text "Name : "
                    button:
                        key_events True
                        action VariableInputValue( "save_name" ).Toggle()

                        input:
                            value VariableInputValue('save_name')
                            length 120
                            allow "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789?!,. -/*":
                            #style whateverYouWant
            # ---->

            ## The grid of file slots.
            grid 5 2:
                style_prefix "slot"
[...]

Making the edit button is easy enough (see delete button), but I cant figure out how to change the value of FileSaveName(slot) once it's been set during the save function. Does anyone have any ideas on how to edit this variable once it's been set?
Since you talk about an "edit button", I guess that you want to rename an already saved file.

Well, for this you need to:
  1. Open the zip file that contain this save ;
  2. Edit the "json." file inside it ;
  3. Change the value of its "_save_name" field ;
  4. Save the updated "json." file in place of the old one inside the zip.


Edit: Updated the code to include crabsinthekitchen comment.
 
Last edited:
  • Red Heart
Reactions: RGilft

OhWee

Forum Fanatic
Modder
Game Developer
Jun 17, 2017
5,660
28,491
Nowadays games mostly rely on a less intrusive, and therefore less annoying, approach than a popup window:
Python:
screen file_slots(title):

    default page_name_value = FilePageNameInputValue(pattern=_("Page {}"), auto=_("Automatic saves"), quick=_("Quick saves"))

    use game_menu(title):

        fixed:
[...]
                input:
                    style "page_label_text"
                    value page_name_value

            # <----
            if title == "Save":
                hbox:
                    text "Name : "
                    input:
                        value VariableInputValue('save_name')
                        length 120
                        allow "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789?!,. -/*":
                        #style whateverYouWant
            # ---->

            ## The grid of file slots.
            grid 5 2:
                style_prefix "slot"
[...]



Since you talk about an "edit button", I guess that you want to rename an already saved file.

Well, for this you need to:
  1. Open the zip file that contain this save ;
  2. Edit the "json." file inside it ;
  3. Change the value of its "_save_name" field ;
  4. Save the updated "json." file in place of the old one inside the zip.
the value for FileSaveName is set ingame, and asking a user to have to exit the game and go through all of those steps just to edit the description is a VERY obtrusive and unreasonable approach. At that point, I'd just tell them to load the save, then save to the same slot (i.e. overwrite it), and re-type the save description however they want.

That's still more steps than I'd like to see though. Essentially, I'd like to see either:

1) the Save description field - as defined in FileSaveName(slot) - can be edited directly by clicking on the text and toggling a cursor
2) an edit button that opens an editing window or toggles the description text, showing the existing text and a cursor that the user can then delete with and add new/modified text, which saves the new value to FileSaveName(slot).

That process could involve loading the save info in the background and then re-saving it when the edit button is clicked (via a script/function), that is invisible to the user, but this approach seems more complicated than it needs to be.


Does anyone ELSE have any thoughts on how to edit the FileSaveName(slot) value once it is set using some action function or such? That doesn't involve the user having to jump though a bunch of hoops?
 
Last edited:
  • Angry
Reactions: anne O'nymous

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,130
14,809
the value for FileSaveName is set ingame,
The value is extracted in real time from the json file stored inside the zip save file, period.

renpy/comon/00action_file.rpy:
Python:
    def FileSaveName(name, empty="", page=None, slot=False):
        return FileJson(name, "_save_name", empty=empty, missing=empty, page=page, slot=slot)

    def FileJson(name, key=None, empty=None, missing=None, page=None, slot=False):
        json = renpy.slot_json(__slotname(name, page, slot))
        if json is None:
            return empty
        if key is None:
            return json
        return json.get(key, missing)
renpy/loadsave.py:
Python:
def slot_json(slotname):
    return get_cache(slotname).get_json()

# A map from slotname to cache object. This is used to cache savegame scan
# data until the slot changes.
cache = { }

def get_cache(slotname):
    rv = cache.get(slotname, None)
    if rv is None:
        rv = cache[slotname] = Cache(slotname)
    return rv
And obviously, changing the value in the cache would have no impact on the value effectively stored in the save file.


and asking a user to have to exit the game and go through all of those steps just to edit the description is a VERY obtrusive and unreasonable approach.
Who ask the user to do this ? I explicitly wrote "you need to", this is obviously something that you have to code yourself. It need a dozen of lines, not really more.


That's still more steps than I'd like to see though.
What you like is one thing, what you can is another.

I explained you the sole and only way to do what you want. What you do with this information is your concern, not mine.


That process could involve loading the save info in the background and then re-saving it [...]
So, that process could involve... exactly what I wrote. Cool, this mean that you'll implement it then.
 

Impious Monk

Active Member
Game Developer
Oct 14, 2021
588
2,516
Nowadays games mostly rely on a less intrusive, and therefore less annoying, approach than a popup window:
Python:
screen file_slots(title):

    default page_name_value = FilePageNameInputValue(pattern=_("Page {}"), auto=_("Automatic saves"), quick=_("Quick saves"))

    use game_menu(title):

        fixed:
[...]
                input:
                    style "page_label_text"
                    value page_name_value

            # <----
            if title == "Save":
                hbox:
                    text "Name : "
                    input:
                        value VariableInputValue('save_name')
                        length 120
                        allow "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789?!,. -/*":
                        #style whateverYouWant
            # ---->

            ## The grid of file slots.
            grid 5 2:
                style_prefix "slot"
[...]



Since you talk about an "edit button", I guess that you want to rename an already saved file.

Well, for this you need to:
  1. Open the zip file that contain this save ;
  2. Edit the "json." file inside it ;
  3. Change the value of its "_save_name" field ;
  4. Save the updated "json." file in place of the old one inside the zip.
Thanks for this code!
 

crabsinthekitchen

Well-Known Member
Apr 28, 2020
1,539
8,413
Nowadays games mostly rely on a less intrusive, and therefore less annoying, approach than a popup window:
Python:
screen file_slots(title):

    use game_menu(title):

        fixed:
[...]
                input:
                    style "page_label_text"
                    value page_name_value

            # <----
            if title == "Save":
                hbox:
                    text "Name : "
                    input:
                        value VariableInputValue('save_name')
                        length 120
                        allow "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789?!,. -/*":
                        #style whateverYouWant

[...]
a small tip, wrap save name input into a button. because without the button, RenPy acts dumb when there's more than one input and if you decide to change the page name, you have to close the screen and open it again to move focus back into save name input
Code:
button:
                        key_events True
                        xalign 0.5
                        yalign 0.0
                        action VariableInputValue('save_name').Toggle()

                        frame:
                            xminimum 256
                            yminimum 38
                            xmaximum 385
                            input:
                                xoffset 5
                                size 23
                                default "[save_name]"
                                value VariableInputValue('save_name')
                                length 30
 
  • Like
Reactions: anne O'nymous

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,130
14,809
Oops, I thought that I already reacted to this, but apparently I was dreaming :(

a small tip, wrap save name input into a button.
Nice catch, haven't though about this issue since I usually use a modified version of the "input".
I updated my code to include it, thanks.
 

Mattock

Newbie
May 27, 2018
86
68
as another example, I dare to promote my mod:Save Game Description
(the download has the "source" .rpy, but the mod does some other things too)

in short I:
-have an input similiar to the Page-Name
-upon save I use the renpy-callback:
config.save_json_callbacks (that should be a list and expects functions)
(-some making sure it's done by a normal save (not auto or quick) )
(-if nothing was entered i.e. a default value: nothing happens)
-I give the json-entry "_save_name" the name entered to the input
-and edit:return the json-object I work on the json-object, therefore it is not returned

additionally I would discourage the use of the (store attribute)("variable") "save_name", because it is IN the "save-game" and will be reloaded;
also always "saved" e.g. on Auto- and Quick-Saves
 
Last edited: