How to check if there are saved games?

Started by Ezekiel000, Sat 04/08/2012 17:46:38

Previous topic - Next topic

Ezekiel000

I want to make it so the title screen for my game either shows just 'new game' or if there is a save game to show 'new game' and 'continue'.
Is this possible?

I found a few ways to do this on google and in the manual but they all seem to be tied to listboxes.
Like here: http://www.adventuregamestudio.co.uk/wiki/?title=Creating_Custom_Save_and_Load_Dialogs

Crimson Wizard

Never tested this myself, but I found this:
http://www.adventuregamestudio.co.uk/wiki/?title=Game_/_Global_functions#Game.GetSaveSlotDescription

From that description I guess you may do so:
Code: ags

if (Game.GetSaveSlotDescription(slot_index) == null)
{
  // save game in this slot does not exist
}
else
{
  // save game exists
}


Now, if you have only one save game allowed, that should do it. If you have unlimited saves allowed, then I have no idea.

Ezekiel000

Thank you that helped I am planning for 6 save slots so I ended up with this code:
Code: AGS
  bool Continue = false;
  if(Game.GetSaveSlotDescription(1) != null) { Continue = true; }
  if(Game.GetSaveSlotDescription(2) != null) { Continue = true; }
  if(Game.GetSaveSlotDescription(3) != null) { Continue = true; }
  if(Game.GetSaveSlotDescription(4) != null) { Continue = true; }
  if(Game.GetSaveSlotDescription(5) != null) { Continue = true; }
  if(Game.GetSaveSlotDescription(6) != null) { Continue = true; }
  if(Continue == false)
  {
    SetBackgroundFrame(1);
    object[0].SetView(5);
    object[0].Animate(1, 3, eRepeat, eNoBlock, eForwards);
    object[0].Visible = true;
	}
  if(Continue == true)
  {
    SetBackgroundFrame(2);
    object[1].SetView(5);
    object[1].Animate(1, 3, eRepeat, eNoBlock, eForwards);
    object[2].SetView(5);
    object[2].Animate(1, 3, eRepeat, eNoBlock, eForwards);
    object[1].Visible = true;
	}	

Crimson Wizard

#3
Just a note.
Since you are repeating same call for N times, usually it is better to do this:
Code: ags

int slot = 1;
while (slot <= 6)
{
   if(Game.GetSaveSlotDescription(slot) != null) { Continue = true; slot = 7; /* to exit while loop right away */ }
   slot++;
}


Also, this:
Code: ags

if (Continue == false)
...
if (Continue == true)

Is perhaps better to do:
Code: ags

if (Continue) // testing boolean variable here, do not need to explicitly compare with value
{
 // true case
}
else // do not need to check variable for the second time, since if it is not true, it is obviously false
{
 // false case
}

Ezekiel000

Thank you, that's much cleaner than my attempt.

SMF spam blocked by CleanTalk