is it possible to test whether a specific save file exists?

I have a game that only permits one save file, and the player can only save their game in a specific kind of room. Saving the game is a big deal! I’m using autosave by @Draconis, so these saves will go wherever the interpreter thinks they should go (like a declared file). This is a typical save file, for those who haven’t worked with Autosave. Something like:

my save file.glksave

This may not really be an autosave question, but rather a general file operation question. I’m not sure!

Saving is a high-stakes thing in this game, so it would be nice to print a verification message.

1 Like

Maybe this will work?

Include (-

[AS_Check      fref;
	fref = glk_fileref_create_by_name( fileusage_SavedGame + fileusage_BinaryMode, Glulx_ChangeAnyToCString(TEXT_TY_Say, autosave_fn), 0 );
	if ( fref ~= 0 )
		if ( glk_fileref_does_file_exist( fref ) ) rtrue;
	rfalse;
];

-).

To decide whether autosave file exists:
	(- (AS_Check()) -).

If you’re not using autosave_fn, then you’ll have to substitute another value.

2 Likes

That’s exactly it! Thanks.

Can i piggyback on this, can the game know if you’ve saved in a specific room?

1 Like

I think the best one could do would be to track the saves in an external file (someone will correct me if I’m off-base). I have thoughts! Just to help out people searching for answers, please create a new topic so the thread title can match the question.