Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: juasma on Sat 24/09/2005 10:31:46

Title: save-load gui problem [SOLVED]
Post by: juasma on Sat 24/09/2005 10:31:46
I have a problem with my load-save gui. It's a lec style gui,  a modified version of the lec minigame of the 2.7 ags demo by RickJ. I searched into the forum but I have not found anything that helps me.
The save gui doesn't seem that it works because not exists slot to choose. If i add a new item to the save list, it saves the game, but if we have various slots saved, when I tried to load or save later, the listbox (the FillSaveGameList() function) has sorted "with the most recent game at the top of the list" , well, actually only sorted the names, not the slots; if I try to load-save the first savegame in the list (the most recent with real file name agssave.00X) I will load-save the first file agssave.000 and not agssave.00X.
I suppose that the solution is easy but I don't see it...

This is the code:

Quote
function ShowSaveGui() {
   gOption.Visible = false;
   gSave.Visible = true;
   gSave.Centre();
   gSaveList.FillSaveGameList();
   ///===================================I added this
      gSaveDescription.SetText("");
        string nada;
        gSaveList.AddItem(nada);
    //===================================End add
}

function ShowLoadGui() {
   gOption.Visible = false;
   gLoad.Visible = true;
   gLoad.Centre();
   gLoadList.FillSaveGameList();
}


sectionstart gSaveOk_Click  // DO NOT EDIT OR REMOVE THIS LINE
function gSaveOk_Click(GUIControl *control, MouseButton button) {
   string buf, buf2;
   DateTime *dt = DateTime.Now;
 
   gSaveDescription.GetText(buf);   
   if ( StrComp(buf, "") != 0 ){    // the text box has name
      SaveGameSlot(gSaveList.SelectedIndex,buf);
      gSave.Visible = false;                       
   }   
  else if ( StrComp(buf, "") == 0 ){ // the text box has no name
      StrFormat(buf2,"%02d/%02d/%04d  %02d:%02d:%02d", dt.DayOfMonth, dt.Month, dt.Year, dt.Hour,

dt.Minute, dt.Second);
      SaveGameSlot(gSaveList.SelectedIndex,buf2);                  
      gSave.Visible = false;         
         } 

}
#sectionend gSaveOk_Click  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart gLoadOk_Click  // DO NOT EDIT OR REMOVE THIS LINE
function gLoadOk_Click(GUIControl *control, MouseButton button) {
   string  buf;
   
   // Make sure slot exists
   if(GetSaveSlotDescription(gLoadList.SelectedIndex,buf)) {
      RestoreGameSlot(gLoadList.SelectedIndex);
      DisplayAt(10,10,50,"%d", gLoadList.SelectedIndex);      
   }
}
#sectionend gLoadOk_Click  // DO NOT EDIT OR REMOVE THIS LINE

Thanks
Title: Re: save-load gui problem
Post by: Pumaman on Sat 24/09/2005 12:45:34
Because FillSaveGameList orders the games with the most recent first, as you've noted the indexes are different.

As it explains in the description of FillSaveGameList in the manual:

The global savegameindex array is updated with the actual slot numbers of the entries. So, you could do:

int index = lstSaveGames.SelectedIndex;
RestoreGameSlot(savegameindex[index]);


So basically, rather than doing this:

Ã,  RestoreGameSlot(gLoadList.SelectedIndex);

you want to do this:

Ã,  RestoreGameSlot(savegameindex[gLoadList.SelectedIndex]);

(and the same probably applies to SaveGameSlot)
Title: Re: save-load gui problem
Post by: juasma on Sat 24/09/2005 15:33:21
Solved! Thanks Pumaman!  :D

The load problem is solved with
QuoteRestoreGameSlot(savegameindex[gLoadList.SelectedIndex]);
but the save need a little more code. This is my solution, it seems that it works correctly:
Quote
#sectionstart gLoadOk_Click  // DO NOT EDIT OR REMOVE THIS LINE
function gLoadOk_Click(GUIControl *control, MouseButton button) {
   string    buf;
   
   // Make sure slot exists
   if(GetSaveSlotDescription(gLoadList.SelectedIndex,buf))
         RestoreGameSlot(savegameindex[gLoadList.SelectedIndex]);      
}
#sectionend gLoadOk_Click  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart gSaveOk_Click  // DO NOT EDIT OR REMOVE THIS LINE
function gSaveOk_Click(GUIControl *control, MouseButton button) {
   string buf, buffer;
   DateTime *dt = DateTime.Now;
   int index = gSaveList.SelectedIndex;
 
   gSaveDescription.GetText(buf);   
   if ( StrComp(buf, "") == 0 )
             StrFormat(buf,"%02d/%02d/%04d  %02d:%02d:%02d", dt.DayOfMonth, dt.Month, dt.Year, dt.Hour, dt.Minute, dt.Second);
 
   gSaveList.GetItemText(gSaveList.SelectedIndex, buffer);
   if (StrComp("", buffer) == 0) 
               SaveGameSlot(gSaveList.SelectedIndex,buf);                     
   else  SaveGameSlot(savegameindex[index],buf);                     
                     
   gSave.Visible = false;                              
}
#sectionend gSaveOk_Click  // DO NOT EDIT OR REMOVE THIS LINE

;D