Page 1 of 1

[Solved] Preview of latest save

Posted: Mon May 02, 2022 2:59 pm
by JungTaco
On the main menu I want to show an image that represents a preview of the chapter where the game was last saved (but not a screenshot like in the save slots). I’m not sure how to do this.
I started something, but it doesn’t seem like a proper solution.

I save the current label in a json whenever the game is saved

Code: Select all

def label_callback(name, abnormal):
    if name.startswith("_"): return
        store.current_label = name
config.label_callback = label_callback

def save_chapter_name(d):
    d["chapter"] = current_label
config.save_json_callbacks.append(save_chapter_name)

I take the name of the newest slot and use it to get the label name from the json

Code: Select all

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

def last_chapter_saved():
        newest_page, newest_name = newest_slot_tuple()
        return FileJson(newest_name, "chapter")
Depending on what the label is, I decide what chapter the game was saved at last

Code: Select all

def continue_image_button():
    if last_chapter_saved() == "chapter1" or last_chapter_saved() == "ch1_story":
        ...
But I'd have to check for every label in a chapter in order to do this and it doesn't seem like a good solution. Unless there's a way to automatically add all those labels in a list for each chapter.

Re: Preview of latest save

Posted: Mon May 09, 2022 4:21 am
by m_from_space
Well, if this is just about some chapter preview image, it's really simple.

Whenever the game starts entering the new chapter, just save the current chapter inside a variable. In the main menu just read out this variable and show the preview image. You could even name the images according to the string you save.

Code: Select all

default last_chapter = None

label start:
   call chapter_one
   call chapter_two
   return

label chapter_one:
   $ last_chapter = "chapter1"
   ...
   return

label chapter_two:
   $ last_chapter = "chapter2"
   ...
   return

screen preview:
   if last_chapter is not None:
      # images should be named "chapter1.jpg" or "chapter2.png" etc.
      add "[last_chapter]"

Re: Preview of latest save

Posted: Mon May 09, 2022 1:28 pm
by JungTaco
I tried it and the last_chapter variable is always None when I start the game.

Re: Preview of latest save

Posted: Mon May 09, 2022 1:36 pm
by JungTaco
But I saved the variable in a json instead of the current label and it worked, so thanks anyway!