Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: SpacePaw on Sun 14/03/2010 12:16:54

Title: [SOLVED] Help with file write before load?
Post by: SpacePaw on Sun 14/03/2010 12:16:54
Okay. I'm getting mad...All I try to do is save some text file before loading save slot (which idicates which saveslot was loaded last). I specify the path to $SaveGameDir$ but it writes it in the compiled game folder! It happens for loading only :/ - when saving everything is ok
File *output = File.Open("$SAVEGAMEDIR$/ResumeGame.dat", eFileWrite);
I do close the file later. I thought there might be a problem with the fact that the game loads (maybe it screws up the path or something and game doesn't wait for the file to be written before load) - so I made a simple hack:
while(!File.Exists("$SAVEGAMEDIR$/ResumeGame.dat"))
     Wait(10);

but it still saves in the game folder and loads the game normally - like it ignored the loop completely.
And no my savegamedir isn't the game folder - it's in my documents - I checked - Saved files do get written in there. So any ideas?
Title: Re: Help with file write before load?
Post by: Pumaman on Sun 14/03/2010 22:46:54
Can you post the contents of the script function that has this command in it?
Title: Re: Help with file write before load?
Post by: SpacePaw on Mon 15/03/2010 11:33:32
Save button click

if ( GetSelectedSlot ( ) == -1 )
// if there is no slot selected
{
 return;
}
else
{    
 if ( Game.GetSaveSlotDescription ( GetSelectedSlot ( ) ) )
 {
 // if the slot exists
   //Save last used load
   SaveResumeFile();    
   FreezeOptions = false;
   RestoreGameSlot ( GetSelectedSlot ( ) );
 }
}


SaveResumeFile(); content

{
   File *output = File.Open("$SAVEGAMEDIR$/ResumeGame.dat", eFileWrite);
 output.WriteInt(GetSelectedSlot());
 output.Close();
    //HERE I INSERTED THE HACK BUT IT DIDN'T HELP AT ALL
}


SaveResumeFile() works just fine when called when saving game...Did I forget about something?
Title: Re: Help with file write before load?
Post by: Shane 'ProgZmax' Stevens on Mon 15/03/2010 15:03:02
Is this meant for something like a continue feature when you start the game?  If so, a real quick workaround that doesn't involve writing files at all would be to have a special save slot that is overwritten each time a new save is made with the same data as that save (kind of like a quicksave).  Then when you choose continue or whatnot it restores from the special slot. 
Title: Re: Help with file write before load?
Post by: SpacePaw on Mon 15/03/2010 17:32:30
Good thinking Progz! outside the box :) But still that thing bothers me because who knows when I'll need to save some information to the file before load...

For now your idea sounds great though, thank you :)
Title: Re: Help with file write before load?
Post by: SpacePaw on Mon 15/03/2010 17:46:39
AAAH! MY FAULT MY FAULT! I tried to do what progz suggested and I deleted whole save .dat file but...it still did save it. That's when i realized that there's some code executing before my function - And I found it! I forgot to delete one old function which did all that mess _-_
So sorry about that :/