Calling variables from saved games for the Save/Load screen

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
Binary Chaos
Newbie
Posts: 1
Joined: Sat Sep 13, 2014 12:31 pm
IRC Nick: Binary_Chaos
Location: Behind you
Contact:

Calling variables from saved games for the Save/Load screen

#1 Post by Binary Chaos »

I'm looking to utilize multiple variables for my Save/Load screen's display, but I seem to have hit a snag since the only way I know how to do so is via the FileSaveName(i) function, which seems capable of facilitating only one string at a time. That is to say, any attempts to cite non "save_name" variables in the context of "File_Picker" will only show the variable's current value in the active game.

For context, my plan was to display a couple of images and a Chapter/Act description in each save file's display area with content dependent on in-game information from each save. Unfortunately, I struck this problem before I had a chance to get the concept down enough to properly put it into code, otherwise I would have posted the corresponding script for reference.

User avatar
BlueScorpion
Newbie
Posts: 14
Joined: Thu Jul 25, 2013 4:01 am
Contact:

Re: Calling variables from saved games for the Save/Load scr

#2 Post by BlueScorpion »

I don't know if there's a way to read other variables from the save file, but exploiting save_name to this effect may work.

Your save_name will look something like this.

Code: Select all

$save_name='1|The Beginning'
This function will break it up.

Code: Select all

init python:
    def get_extra_stuff(data):
        if '|' in data:
            chapter, title = data.split('|', 1)
        else:
            chapter = ''
            title = data
        return (chapter, title)
The relevant part in file_picker screen to change.

Code: Select all

                    # Format the description, and add it as text.
                    $ chapter, title = get_extra_stuff(FileSaveName(i))
                    $ description = ("% 2s. %s\n%s" % (
                        FileSlotName(i, columns * rows),
                        FileTime(i, empty=_("Empty Slot.")),
                        title))

                    text description

                    if chapter == '1':
                        ## do whatever you wanted to do with the information
                        null width 0
                    elif chapter == '2':
                        ## and etc
                        null width 0
You could break it into as many parts as you wanted this way.

User avatar
PyTom
Ren'Py Creator
Posts: 16093
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: Calling variables from saved games for the Save/Load scr

#3 Post by PyTom »

You want to use the relatively new JSON support.

You add json to a file using a function added to config.save_json_callbacks, and retrieve it with FileJson.

As an example, you can persist the save_image variable on a per-save-slot basis, using:

Code: Select all

init python:
     def add_save_image(d):
          d["save_image"] = getattr(store, "save_image", "unknown.png")
     config.save_json_callbacks = add_save_image
And to access it from the load screen, you add:

Code: Select all

add FileJson(slot, "save_image", empty=Null(), missing="unknown.png")
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

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]