using SaveGameSlot function in an autosave feature

Started by Lizo, Mon 13/07/2009 19:35:20

Previous topic - Next topic

Lizo

I recently updated to a current version of AGS (3.1.2) from a very old version (2.6 or thereabouts), and I'm running into some trouble using the SaveGameSlot function as part of an autosave feature in a game that I'm working on.  The trouble, I believe, comes from the fact that SaveGameSlot queues until the end of the current script, no matter when it is called.  In the old version of AGS that I had been using, if I called SaveGameSlot right at the beginning of an action that would cause the player character to die, the game would be safely autosaved and could be loaded again to that exact point, just before the death.  Now, however, since the function waits until the end of the script to execute, the autosave function only kicks in after the character has died, and the saved file is pretty much useless to the player.

So basically, my question is this:  Is there any way to get SaveGameSlot to execute before the current script finishes running?

Khris

Is this for some kind of undo functionality? Couldn't you simply reset the game manually to the state it was in before after the player clicked "retry"?

monkey0506

Khris may have a point as while the game is still loaded and you're just at the "you died" screen there shouldn't be too much additional data you would need to store. However if you wanted to go with the auto-save route you could do something like:

Code: ags
// global script
bool autosave = false; // export/import as necessary; whether we have just saved the autosave slot

function on_event(EventType event, int data) { // if you're already using on_event just add these lines
  if (event == eEventRestoreGame) {
    if (data == 998) autosave = false; // we just restored the autosave slot, make sure we don't loop back to the player dying!
  }
}

// player dies
SaveGameSlot(998);
autosave = true;

// repeatedly_execute
// the rest of your "die" interactions
// send the player to the appropriate room, display a message, GUI, whatever


By setting a flag to let us know when we've saved our autosave slot we can then use the rep_ex function to check that flag. The function in which we performed the save will complete (i.e., the slot will be saved) before we get to the rep_ex function and see the state of the flag. Thereby we know when the slot has been saved and can continue on.

This is precisely the way that RickJ performed autosaves for his MiniGame module, saving the state of the game right before he loads the minigame.

Dualnames

I'm using an autosave and hell it was easy to do

I've put everytime player does something right, this:
SaveGameSlot(48,"Autosave");

and guess what on Undo button
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Lizo

OK, thanks for the suggestions, everyone.  I'll play around with a few different ideas and see what works best in my situation.  Thanks!

SMF spam blocked by CleanTalk