[SOLVED] Help with file write before load?

Started by SpacePaw, Sun 14/03/2010 12:16:54

Previous topic - Next topic

SpacePaw

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
Code: ags
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:
Code: ags
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?

Pumaman

Can you post the contents of the script function that has this command in it?

SpacePaw

#2
Save button click
Code: ags

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
Code: ags

{
    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?

Shane 'ProgZmax' Stevens

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. 

SpacePaw

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 :)

SpacePaw

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 :/

SMF spam blocked by CleanTalk