Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Ubel on Thu 18/05/2006 16:10:08

Title: Checking if a certain file exists
Post by: Ubel on Thu 18/05/2006 16:10:08
I'm making a save GUI. I need to know how I can check if a certain agssave-file already exists. For example, let's say I want to check if "agssave.001"-file exists. What kind of scripting should I use for this?

This is because I want to make sure my save GUI doesn't save over any agssave file if it already exists in the compiled folder.

I hope you know what I mean. Thanks. :)
Title: Re: Checking if a certain file exists
Post by: strazer on Thu 18/05/2006 16:15:49

  File *thefile = File.Open("agssave.001", eFileRead);
  if (thefile == null) {
    Display("Error opening file."); // i.e. file probably doesn't exist
  }
  else {
    // do stuff
    thefile.Close();
  }
Title: Re: Checking if a certain file exists
Post by: Ubel on Thu 18/05/2006 16:24:53
Ah yes, I thought it would be done in a similiar way with File.Open. I just didn't know how exactly this could be done, but apparently it's very simple. Thanks for the quick answer.
Title: Re: Checking if a certain file exists
Post by: strazer on Thu 18/05/2006 16:26:28
No prob. :)
Title: Re: Checking if a certain file exists
Post by: Dr. Scary on Thu 18/05/2006 16:42:52
Or you could use the even simpler method that the manual suggests:

Quote
GetSaveSlotDescription
(Formerly known as global function GetSaveSlotDescription, which is now obsolete)

static String Game.GetSaveSlotDescription(int slot)
Gets the text description of save game slot SLOT.
If the slot number provided does not exist, returns null.