Is it possible to read variable value from save data? [SOLVED]

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
mikolajspy
Regular
Posts: 169
Joined: Sun Jun 04, 2017 12:05 pm
Completed: Too many, check signature
Deviantart: mikolajspy
Location: Wrocław, Poland
Contact:

Is it possible to read variable value from save data? [SOLVED]

#1 Post by mikolajspy »

Hi!
I started working on my next project and I'm in designing phase, and I couldn't find the answer if what I want is even possible.

Can I somehow read variable from Ren'Py save?

Example: During game you gather affection points defined as 'default' variable, and I'd like to display these points on top of save thumbnail, so the player can have better idea from which "route" the save is.

I'd love something like $renpy.getsavevariable(slotname, variablename), but documentation seems silent about reading specific variables from save, or any variables at all.
Persistent variable won't work, since affection points will be specific to each gameplay.
Last edited by mikolajspy on Wed Oct 18, 2017 4:53 pm, edited 1 time in total.

User avatar
xavimat
Eileen-Class Veteran
Posts: 1460
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love, unknown
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Contact:

Re: Is it possible to read variable value from save data?

#2 Post by xavimat »

A quick guess.
You could use the variable save_name to add that info. It will be shown in the load screen.
https://www.renpy.org/doc/html/save_loa ... -save_name
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

mikolajspy
Regular
Posts: 169
Joined: Sun Jun 04, 2017 12:05 pm
Completed: Too many, check signature
Deviantart: mikolajspy
Location: Wrocław, Poland
Contact:

Re: Is it possible to read variable value from save data?

#3 Post by mikolajspy »

I'm actually using that to write chapter and location. The problem is, too many information in text would look bad on save, so I wanted to display these "affection points" more graphically as overlay on save thumbnail or some other way, not as text in save name.

philat
Eileen-Class Veteran
Posts: 1900
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Is it possible to read variable value from save data?

#4 Post by philat »

1. You could save everything in the save name and break that data up to display separately (e.g., save_name is something like "Chapter/Location/Var 1/Var 2" and you split that by slash).

2. You could save to json. Search the forum for examples, but here's one. viewtopic.php?p=428861#p428861

mikolajspy
Regular
Posts: 169
Joined: Sun Jun 04, 2017 12:05 pm
Completed: Too many, check signature
Deviantart: mikolajspy
Location: Wrocław, Poland
Contact:

Re: Is it possible to read variable value from save data?

#5 Post by mikolajspy »

philat wrote: Sun Oct 08, 2017 1:13 am 2. You could save to json. Search the forum for examples, but here's one. viewtopic.php?p=428861#p428861
Awesome! Thank you very much, it's exactly what I needed!

mikolajspy
Regular
Posts: 169
Joined: Sun Jun 04, 2017 12:05 pm
Completed: Too many, check signature
Deviantart: mikolajspy
Location: Wrocław, Poland
Contact:

Re: Is it possible to read variable value from save data?

#6 Post by mikolajspy »

OK, so I got JSON working for affection points and it nicely appears in the corner, but as I programmed more story I came upon another issue.
I'm using following code:

Code: Select all

default save_name = "Chapter [Chapter] | [Location]"
Where [Chapter] and [Location] are variables set depending on story progression.
The problem is, whenever I got into Chapter 2 and/or change location, it changes even on previously saved files in menu! As if it took variables from current session, and not stored in save.

Is my only way to work it out, for example, make function that checks when and where player is, and based on that assign static string to save_name?
I think I'd go with that, since player can be in various locations in one chapter, as well as on other chapters, so it'd be easier to change one variable and call function at the beginning of label.

Example

Code: Select all

def SetSaveName():
    if Chapter == 1 and Location == "City":
        $ save_name = "Chapter 1 | City"
    if Chapter == 1 and Location == "Home":
        $ save_name = "Chapter 1 | Home"
     #... and so on 
If someone has better ideas, please let me know.

Post Reply

Who is online

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