[Solved] Preview of latest save

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
JungTaco
Newbie
Posts: 5
Joined: Mon Apr 18, 2022 1:38 pm
Contact:

[Solved] Preview of latest save

#1 Post by JungTaco » Mon May 02, 2022 2:59 pm

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.
Last edited by JungTaco on Wed Jun 01, 2022 5:48 am, edited 1 time in total.

User avatar
m_from_space
Veteran
Posts: 302
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Preview of latest save

#2 Post by m_from_space » Mon May 09, 2022 4:21 am

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]"

JungTaco
Newbie
Posts: 5
Joined: Mon Apr 18, 2022 1:38 pm
Contact:

Re: Preview of latest save

#3 Post by JungTaco » Mon May 09, 2022 1:28 pm

I tried it and the last_chapter variable is always None when I start the game.

JungTaco
Newbie
Posts: 5
Joined: Mon Apr 18, 2022 1:38 pm
Contact:

Re: Preview of latest save

#4 Post by JungTaco » Mon May 09, 2022 1:36 pm

But I saved the variable in a json instead of the current label and it worked, so thanks anyway!

Post Reply

Who is online

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