Hello community,
I have a possibly weird question: Is it possible to check, if the player has saved? Preferably if the player saved recently (like, in the last 5 minutes / since variable X was activated)?
I would like to make a meta-game where the game asks you to save someone BY SAVING THE GAME.
But I am not certain how to make Renpy check the save files for something like a time stamp or such. Or how to tell Renpy that - once variable x has been activated - it should put variable Y on active in the permanent data if the player changes something about the save files.
If it's not possible, then that is ok, but if there is a way, then I'd appreciate the help!
Check if Player saved [[SOLVED]]
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.
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.
- MoonByte
- Regular
- Posts: 173
- Joined: Thu Mar 24, 2016 9:18 pm
- Completed: Shine (RPG Maker), Heroes (RPG Maker), Lantern Bearer (RPG Maker), Loop the Loop (Unity), Other Stars (Unreal), Sky Eye (RPG Maker), WIN Delivery & Fateful (Ren'Py)
- Projects: Weird Is Normal (Ren'Py)
- Location: Germany
- Contact:
Check if Player saved [[SOLVED]]
Last edited by MoonByte on Fri May 26, 2017 3:50 am, edited 1 time in total.
- Ocelot
- Lemma-Class Veteran
- Posts: 2400
- Joined: Tue Aug 23, 2016 10:35 am
- Github: MiiNiPaa
- Discord: MiiNiPaa#4384
- Contact:
Re: Check if Player saved
RenPy abstracts interacting with filesystem and, for the sake of portability, I would not mess with that.
Instead, you can save some information (save time, important variable state, etc.) alongside saves:
Add a custom function to save_json_callbacks config variable, then, when you need it, extract information about saves, by iterating list of all saves and using slot_json function, or FileJson screen action.
Instead, you can save some information (save time, important variable state, etc.) alongside saves:
Add a custom function to save_json_callbacks config variable, then, when you need it, extract information about saves, by iterating list of all saves and using slot_json function, or FileJson screen action.
< < insert Rick Cook quote here > >
- MoonByte
- Regular
- Posts: 173
- Joined: Thu Mar 24, 2016 9:18 pm
- Completed: Shine (RPG Maker), Heroes (RPG Maker), Lantern Bearer (RPG Maker), Loop the Loop (Unity), Other Stars (Unreal), Sky Eye (RPG Maker), WIN Delivery & Fateful (Ren'Py)
- Projects: Weird Is Normal (Ren'Py)
- Location: Germany
- Contact:
Re: Check if Player saved
Oh, I see!
I'll try and see, if I can do that, thanks!
EDIT:
So I looked into it (and other JSON code threads here), but while I can change the save file, I can't manipulate it exactly in the way I want (I assume, I am placing stuff at the wrong places or so).
To run a test, I put this into init based on this thread:
The idea is that I have my game running and ONLY when trigger is True, would the game add to savings. So that I can then look once the trigger was activated, if the player has saved.
I have went through screen.rpy and tried out multiple places where I added
But it's either not that easy or I am not able to figure out which code in screens is the one that actually saves.
I might be wrong, but if looking at the code, I'd even say that Ren'Py has the save code NOT in the game files, but probably in it's own? Which makes me question even more how to work with my initial idea (unless I didn't fully understand JSON, which is also possible since I haven't ever even heard of this in relation to Phyton yet).
I'll try and see, if I can do that, thanks!
EDIT:
So I looked into it (and other JSON code threads here), but while I can change the save file, I can't manipulate it exactly in the way I want (I assume, I am placing stuff at the wrong places or so).
To run a test, I put this into init based on this thread:
Code: Select all
init python:
trigger = False
savings = 0
def my_save(data):
data["my_savings"] = savings
config.save_json_callbacks = [ my_save ]
Code: Select all
label start:
e "We can't do anything here without you."
e "There is just no way."
e "I don't even know what to say..."
$ trigger = True
e "Unless you save them."
e "You need to do it!"
e "Please!"
if savings >= 1:
e "Thank you!"
e "I knew you would help us!"
else:
e "Why aren't you doing anything?!"
e "Why?!"
Code: Select all
if trigger == True:
$ savings += 1
# include save code
else:
# include save code
I might be wrong, but if looking at the code, I'd even say that Ren'Py has the save code NOT in the game files, but probably in it's own? Which makes me question even more how to work with my initial idea (unless I didn't fully understand JSON, which is also possible since I haven't ever even heard of this in relation to Phyton yet).
- Ocelot
- Lemma-Class Veteran
- Posts: 2400
- Joined: Tue Aug 23, 2016 10:35 am
- Github: MiiNiPaa
- Discord: MiiNiPaa#4384
- Contact:
Re: Check if Player saved
Here is an example of using json information in saves. Create a new project and replace content of script.rpy
Code: Select all
define help = Character('Help')
# By defult we do not know about ambush.
# It is only set at specific point of the game.
default ambush_knowledge = False
init python:
# A function which takes a dictionary and saves value of ambush_knowledge as extra data
def save_extra_info(d):
d['ambush_knowledge'] = ambush_knowledge
# We need to add this function to list of callbacks to actually invoke it as part of save process
config.save_json_callbacks.append(save_extra_info)
# A function to check if we know about ambush in any of the save files
def check_ambush_knowledge():
# Iterate over list of all save file names
for name in renpy.list_saved_games(fast=True):
# Extract extra info
json = renpy.slot_json(name)
# Get save value of ambush_knowledge. We are protected from both
# missing JSON info and missing 'ambush_knowledge' record
# this can happen if we add this logic later in later patch and someone has save from previous version
knows_about_ambush = json.get('ambush_knowledge', False) if json else False
if knows_about_ambush:
return True
return False
# A help center to hint about need to save in certain moment
label knowledge_corner:
help 'You died.'
help 'Well, you had no way to know, what expect you behind that door, right?'
help 'If only you could {color=#00F}remember{/color}...{p}If only there was a way to {color=#00F}save{/color} those memories...'
help 'Maybe then you could find another way out?'
return
label start:
'You see a door. There is something written on the door:'
'{i}Enter here{/i}'
menu:
'Enter':
'The door slammed shut behind you.'
$ ambush_knowledge = True # All games saved after that line will pass ambush_knowledge check
'Suddenly light flooded the room.'
'You saw dozens of soldiers surrounding you.'
'It is a trap!'
'Commander' 'Fire!'
'You died before you even heard first gunshot.'
$ ambush_knowledge = False # If you didn't save before, you missed the moment.
# Show hint if you did not do the right thing
if not check_ambush_knowledge():
call knowledge_corner
centered 'YOU HAVE LOST'
# This option will only be avaliable if you have a game saved in the ambush scenario
"Don't enter" if check_ambush_knowledge():
'Knowing well, what waits for you behind those doors, you decide not to enter.'
'You eveaded the trap!'
centered 'YOU HAVE WON'
return
< < insert Rick Cook quote here > >