Add text to save slot

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
voluorem
Regular
Posts: 29
Joined: Fri Jun 24, 2022 3:32 pm
Projects: Sweet Release
Discord: voluorem
Contact:

Add text to save slot

#1 Post by voluorem »

So my game has a time of day variable (either morning, afternoon, evening, or night), and I want to show that variable on the save slot when you save. I tried just putting it in the save slot name, which does work, but it looks like this:
Image
And I want it to look like this (done by just adding new lines, but it messes up if the date only takes up one line):
Image

I know I need to save it with JSON somehow, but I cannot for the life of me figure out how to implement JSON into Renpy. The documentation doesn't really have much about it and I can't find any examples similar to what I'm trying to do. I just want it to be a separate block of text (like the playtime) that I can position wherever.

Or honestly, if there's a way to make it be on the 5th line regardless of how many total lines the save name is, that also works lol. I don't think the date will ever be more than 2 lines, but it definitely will sometimes only be one.

Here's my save screen code, if that helps at all:

Code: Select all

screen diary_screen():
    frame:
        xpos 300
        ypos 100
        background None
        has vbox

        hbox:
            ypos -5
            style_prefix "fileslot"
            imagebutton:
                idle "gui/button/left.png"
                ypos 12
                action FilePagePrevious(max=3)
            if config.has_quicksave:
                textbutton _("{#quick_page}Q") action FilePage("quick")
            for i in range(1, 4):
                textbutton str(i) action FilePage(i)
            imagebutton:
                idle "gui/button/right.png"
                ypos 12
                action FilePageNext(max=3)

        if loadorsave == "load":
            grid 1 2:
                transpose True
                xfill True
                spacing 25
                for i in range(1, 3):
                    textbutton (FileSaveName(i)):
                        style_prefix "myslots"
                        action [SetVariable("save_name", "%s"%calendar.string3()), FileLoad(i)]
                        xfill True
        else:
            grid 1 2:
                transpose True
                xfill True
                spacing 25
                for i in range(1, 3):
                    button:
                        text (FileSaveName(i)) ypos 40
                        style_prefix "myslots"
                        action [SetVariable("save_name", "%s"%calendar.string3()), FileSave(i)]
                        xfill True
                        $ playtime = FileJson(i, "playtime", empty=0, missing=0)
                        $ minutes, seconds = divmod(int(playtime), 60)
                        $ hours, minutes = divmod(minutes, 60)
                        text "[hours:02d]:[minutes:02d]:[seconds:02d]" ypos 146 xpos 250
                        $ tod_save = FileJson(i, key="tod")
                        text "[tod_save]" ypos 146 xpos 40

        textbutton "Save":
            text_style "fileslot_button_text" xpos 600 ypos -80 action SetVariable("loadorsave", "save")
        textbutton "Load":
            text_style "fileslot_button_text" xpos 600 ypos -90 action SetVariable("loadorsave", "load")
And this is calendar.string3:

Code: Select all

def string3(self):
                return "%s, %s %d\n\n\n%s"%(self.weekday(), self.month_names[self.month], self.day, tod.capitalize())

User avatar
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Add text to save slot

#2 Post by _ticlock_ »

voluorem wrote: Mon Nov 28, 2022 10:50 pm
You have two options:
1) Add a separator (for example #) between game date and game time of day and use the split function to distinguish them:

Code: Select all

def string3(self):
                return "%s, %s %d#%s"%(self.weekday(), self.month_names[self.month], self.day, tod.capitalize())

Code: Select all

button:
    #game date
    text (FileSaveName(i).split('#')[0]) ypos 40
    #game tod
    text (FileSaveName(i).split('#')[1]) ypos 146 xpos 40
2)Add time of day separately from filename to the save file using jsoncallback function like you did with playtime

Code: Select all

init python:
    def jsoncallback(d):
        d["playtime"] = #The code you used for getting playtime
        d["tod"] = store.calendar.tod.capitalize()

    config.save_json_callbacks = [jsoncallback]

Code: Select all

button:
    #game tod
    text FileJson(i, "tod", empty="", missing="") ypos 146 xpos 40

Post Reply

Who is online

Users browsing this forum: No registered users