Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: shaun9991 on Sun 07/08/2022 18:01:10

Title: Auto-loading the most recent save slot [SOLVED]
Post by: shaun9991 on Sun 07/08/2022 18:01:10
Hey!

I have an "on key press" autoload function set up in my game. If the player presses F5, the game autosaves to slot 98. If the player presses F7, it loads up the autosave slot (98).

Code (ags) Select
  if(keycode == eKeyF7){
   RestoreGameSlot(98);
   UnPauseGame();
}


How can I change this so that pressing the F7 key will actually load up the most recent save game in general? And how would I put a check in place in case no save games exist? Any help is much appreciated, I've been fiddling around with various possibilities but haven't managed to get it working.

ps. I use the standard AGS Load/Save system detailed here: https://www.adventuregamestudio.co.uk/wiki/Creating_Custom_Save_and_Load_Dialogs

Many thanks!
Shaun
Title: Re: Auto-loading the most recent save slot
Post by: Crimson Wizard on Sun 07/08/2022 18:07:33
When you fill the list box using ListBox.FillSaveGameList, it sorts the saves by date (most recent first). You may create a hidden list box, fill it, and choose the first item in ListBox.SaveGameSlots[] array (SaveGameSlots[0]). If ListBox.ItemCount is zero, that would mean that there are no saves.
Title: Re: Auto-loading the most recent save slot
Post by: shaun9991 on Mon 08/08/2022 10:08:22
Thanks CW! :)

I'll try this out this evening.
Title: Re: Auto-loading the most recent save slot
Post by: shaun9991 on Mon 08/08/2022 16:58:31
It works! Thanks CW :)