This request may be a bit of a pain, but I don’t have the I6 abilities for it.
I’m looking to add use of a saved game state to my Guide Mode extension. This will get around an online issue where Parchment doesn’t save the UNDO stack. So atm, if you return to a game that was in guide mode via Parchment’s autosave, you’ll find the mode’s broken. @kamineko pointed this out to me. I’ll change the extension so it maintain’s the one required snapback point itself as a saved file.
I have a pile of code for manual saving/loading that I think I originally got from Kerkerkruip eons ago, and I assume it’s now as old as 6G60. I also assume it was derived from the general save/load routines. Basically it uses four custom i6 functions. I’ll paste the functions and their code at the bottom.
-
I’m looking for an Inform 10.x version of the whole thing to fix the extension. This is the higher priority.
-
Separately, I’m looking for 6M62 versions of the i6 functions, because I derived my extension from my WIP, which is in 6M62, so I need it working there as well.
-
Also, I’m hazy on the use of the ‘To set BLAH as a save file’ function?
Thanks for taking a look.
-Wade
Summary
A save slot is a kind of thing. slot 1 is a save slot.
A save slot has an external file called the savedata.
The binary file of slot 1 is called "manual-save1". The savedata of slot 1 is the file of slot 1.
An external file can be a save file.
the file of slot 1 is a save file.
To save manually:
write_savedata to savedata of slot 1;
To load manually:
load_savedata savedata of slot 1;
To load_savedata (filename - save file external file):
(- FileIO_LoadSavedGame({filename}); -).
To write_savedata to (filename - save file external file):
(- FileIO_WriteSavedGame({filename}); -).
To set (filename - external file) as a save file:
(- FileIO_SetSaveFile( {filename} ); -).
To decide if save (filename - external file) exists:
(- (FileIO_SavedGameExists({filename}, false)) -).
Include (-
[ FileIO_LoadSavedGame extf struc fref res;
if ((extf < 1) || (extf > NO_EXTERNAL_FILES))
return FileIO_Error(extf, "tried to access a non-file");
struc = TableOfExternalFiles-->extf;
fref = glk_fileref_create_by_name(fileusage_SavedGame + fileusage_BinaryMode, Glulx_ChangeAnyToCString(struc-->AUXF_FILENAME), 0);
if (fref == 0) jump RFailed;
gg_savestr = glk_stream_open_file(fref, $02, GG_SAVESTR_ROCK);
glk_fileref_destroy(fref);
if (gg_savestr == 0) jump RFailed;
@restore gg_savestr res;
glk_stream_close(gg_savestr, 0);
gg_savestr = 0;
rtrue;
.RFailed;
CarryOutActivity( (+ failing to restore from a saved game +) );
];
[ FileIO_WriteSavedGame extf struc fref res;
if (actor ~= player) rfalse;
if ((extf < 1) || (extf > NO_EXTERNAL_FILES))
return FileIO_Error(extf, "tried to access a non-file");
struc = TableOfExternalFiles-->extf;
fref = glk_fileref_create_by_name(fileusage_SavedGame + fileusage_BinaryMode, Glulx_ChangeAnyToCString(struc-->AUXF_FILENAME), 0);
if (fref == 0) jump SFailed;
gg_savestr = glk_stream_open_file(fref, $01, GG_SAVESTR_ROCK);
glk_fileref_destroy(fref);
if (gg_savestr == 0) jump SFailed;
@save gg_savestr res;
if (res == -1) {
! The player actually just typed "restore". We have to recover all the Glk objects;
! the values in our global variables are all wrong.
GGRecoverObjects();
glk_stream_close(gg_savestr, 0); ! stream_close
gg_savestr = 0;
CarryOutActivity( (+ restoring from a saved game +) );
rtrue;
}
glk_stream_close(gg_savestr, 0); ! stream_close
gg_savestr = 0;
if (res == 0) CarryOutActivity( (+ automatically saving the game +) ); rtrue;
.SFailed;
CarryOutActivity( (+ failing to automatically save the game +) );
];
[ FileIO_SavedGameExists extf fref struc rv usage;
if ((extf < 1) || (extf > NO_EXTERNAL_FILES)) rfalse;
struc = TableOfExternalFiles-->extf;
if ((struc == 0) || (struc-->AUXF_MAGIC ~= AUXF_MAGIC_VALUE)) rfalse;
if (struc-->AUXF_BINARY) usage = fileusage_BinaryMode;
else usage = fileusage_TextMode;
fref = glk_fileref_create_by_name(fileusage_SavedGame + usage,
Glulx_ChangeAnyToCString(struc-->AUXF_FILENAME), 0);
rv = glk_fileref_does_file_exist(fref);
glk_fileref_destroy(fref);
return rv;
];
[ FileIO_SetSaveFile extf struc;
if ((extf < 1) || (extf > NO_EXTERNAL_FILES))
return FileIO_Error(extf, "tried to access a non-file");
struc = TableOfExternalFiles-->extf;
struc-->AUXF_BINARY = struc-->AUXF_BINARY | 2;
];
-).