Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: BernieLaraemie on Tue 26/07/2005 04:57:31

Title: Save Game Dialog Issues
Post by: BernieLaraemie on Tue 26/07/2005 04:57:31
I'm using AGS 2.7, and I've written a save game script off of Proskrito's MI2 template.  It's been upgraded, and it works, save for a few issues:

--label on Savetext GUI is always 1
--Will only save to slot 1

I figure it's a problem with lstSAVE/REST.Selectedindex, but I'm out of things to change.

Here is the script:

if (interface == SAVE) {
  int index;
  lstSAVE.SelectedIndex = index;
  if (button == 0) {gSave.Visible = false; //cancel
              gSavetext.Visible = false;
                              }
  if (button == 1) {int slist; //listbox
              StrFormat(buffer, "%d", index+1);
              lblNUM.SetText(buffer);
              if (GetSaveSlotDescription(index+100,buffer)==0) StrCopy(buffer,"");
              txtSAVE.SetText(buffer);
              slist=75+((index-GStopsaveitem)*(DEFAULT_FONT_HEIGHT+2));
              if (index<9) txtSAVE.SetPosition(12, 0);
             else txtSAVE.SetPosition(18, 0);
            gSavetext.SetPosition(79, slist);
            gSavetext.Visible = true;                                                            
   }
    if (button == 2 && index>=0) {   //save game                                    
txtSAVE.GetText(buffer);
gSave.Visible = false;                                          
gSavetext.Visible = false;
SaveGameSlot(index+100, buffer);
                                                   }



    if (button == 3){//scroll up
                               gSavetext.Visible = false;
                lstSAVE.SelectedIndex = -1;
          if (GStopsaveitem<5) GStopsaveitem=0;
                         else GStopsaveitem-=5;
          lstSAVE.TopItem = GStopsaveitem;
                              }

    if (button == 4 && GStopsaveitem<90){ //scroll down
            gSavetext.Visible = false;
            lstSAVE.SelectedIndex = -1;
              GStopsaveitem+=5;
              lstSAVE.TopItem = GStopsaveitem;
   }


}

if (interface == SAVETEXT){
      int index2;
      lstSAVE.SelectedIndex = index2;
     
if (button == 0){ //write save name
            txtSAVE.GetText(buffer);     
            gSave.Visible = false;
            gSavetext.Visible = false;
                                 SaveGameSlot(index2+100,buffer);
                                 }
    if (IsButtonDown(RIGHT)) gSavetext.Visible = false; //turn off GUI


}

if (interface == LOAD) {
    if (button ==4) gLoad.Visible = false; //cancel
    if (button ==2){ //click on listbox item
            int index3;
            lstREST.SelectedIndex = index3;
            if (GetSaveSlotDescription(index3 + 100, buffer)==1) { //if saved games exist
            gLoad.Visible = false;
            RestoreGameSlot(index3+100);
        }
       }
   
    if (button == 0){ //scroll up
         if (GStopsaveitem<5) GStopsaveitem=0;
         else GStopsaveitem-=5;
         lstREST.TopItem = GStopsaveitem;
            }
    if (button == 1 && GStopsaveitem<90) { //scroll down
      GStopsaveitem+=5;
      lstREST.TopItem = GStopsaveitem;
     
    }
   
   

   
}

Any help is very appreciated, thank you.

~~Bernie
Title: Re: Save Game Issues
Post by: Gilbert on Tue 26/07/2005 06:29:35
I'm too lazy to check all the codes at the moment, but bear in mind that variables declared inside of a function are not initialized, so pairs of codes like below may generate unexpected results:
Ã,  int index;
Ã,  lstSAVE.SelectedIndex = index;
(It may even generate a crash if index is set to some out of range value when declared).

I'm too lazy, but try initialising the variables and see if that helps:

if (interface == SAVE) {
Ã,  int index=0;
Ã,  lstSAVE.SelectedIndex = index;
Ã,  if (button == 0) {gSave.Visible = false; //cancel
         Ã,  Ã,  Ã, gSavetext.Visible = false;
                              }
Ã,  if (button == 1) {int slist; //listbox
         Ã,  Ã,  Ã, StrFormat(buffer, "%d", index+1);
         Ã,  Ã,  Ã, lblNUM.SetText(buffer);
         Ã,  Ã,  Ã, if (GetSaveSlotDescription(index+100,buffer)==0) StrCopy(buffer,"");
         Ã,  Ã,  Ã, txtSAVE.SetText(buffer);
         Ã,  Ã,  Ã, slist=75+((index-GStopsaveitem)*(DEFAULT_FONT_HEIGHT+2));
         Ã,  Ã,  Ã, if (index<9) txtSAVE.SetPosition(12, 0);
         Ã,  Ã,  else txtSAVE.SetPosition(18, 0);
            gSavetext.SetPosition(79, slist);
            gSavetext.Visible = true;                                                            
   }
Ã,  Ã,  if (button == 2 && index>=0) {   //save game                                    
txtSAVE.GetText(buffer);
gSave.Visible = false;                                          
gSavetext.Visible = false;
SaveGameSlot(index+100, buffer);
                                                   }



Ã,  Ã,  if (button == 3){//scroll up
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, gSavetext.Visible = false;
         Ã,  Ã,  Ã,  Ã, lstSAVE.SelectedIndex = -1;
          if (GStopsaveitem<5) GStopsaveitem=0;
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, else GStopsaveitem-=5;
          lstSAVE.TopItem = GStopsaveitem;
                              }

Ã,  Ã,  if (button == 4 && GStopsaveitem<90){ //scroll down
            gSavetext.Visible = false;
            lstSAVE.SelectedIndex = -1;
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  GStopsaveitem+=5;
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  lstSAVE.TopItem = GStopsaveitem;
Ã,  Ã, }


}

if (interface == SAVETEXT){
      int index2=0;
                  lstSAVE.SelectedIndex = index2;
Ã,  Ã,  Ã, 
if (button == 0){ //write save name
            txtSAVE.GetText(buffer);Ã,  Ã,  Ã, 
            gSave.Visible = false;
            gSavetext.Visible = false;
                                 SaveGameSlot(index2+100,buffer);
                                 }
Ã,  Ã,  if (IsButtonDown(RIGHT)) gSavetext.Visible = false; //turn off GUI


}

if (interface == LOAD) {
Ã,  Ã,  if (button ==4) gLoad.Visible = false; //cancel
Ã,  Ã,  if (button ==2){ //click on listbox item
            int index3=0;
            lstREST.SelectedIndex = index3;
            if (GetSaveSlotDescription(index3 + 100, buffer)==1) { //if saved games exist
            gLoad.Visible = false;
            RestoreGameSlot(index3+100);
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  Ã, }
Ã,  Ã, 
Ã,  Ã,  if (button == 0){ //scroll up
Ã,  Ã,  Ã,  Ã,  Ã, if (GStopsaveitem<5) GStopsaveitem=0;
Ã,  Ã,  Ã,  Ã,  Ã, else GStopsaveitem-=5;
Ã,  Ã,  Ã,  Ã,  Ã, lstREST.TopItem = GStopsaveitem;
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  if (button == 1 && GStopsaveitem<90) { //scroll down
Ã,  Ã,  Ã,  GStopsaveitem+=5;
Ã,  Ã,  Ã,  lstREST.TopItem = GStopsaveitem;
Ã,  Ã,  Ã, 
Ã,  Ã,  }
Ã,  Ã, 
Ã,  Ã, 

Ã,  Ã, 
}

Title: Re: Save Game Issues
Post by: BernieLaraemie on Tue 26/07/2005 07:51:10
:(

Sorry Gilbot.  That had no effect.  Any more ideas from anyone?

~~Bernie
Title: Re: Save Game Issues
Post by: Gilbert on Tue 26/07/2005 08:02:26
Hmmm maybe it's this problem, the SelectedIndex is changed to some fixed value, maybe the correct one is the otherway round:
if (interface == SAVE) {
Ã,  int index;
  indexÃ, = lstSAVE.SelectedIndex;
Ã,  if (button == 0) {gSave.Visible = false; //cancel
         Ã,  Ã,  Ã, gSavetext.Visible = false;
                              }
Ã,  if (button == 1) {int slist; //listbox
         Ã,  Ã,  Ã, StrFormat(buffer, "%d", index+1);
         Ã,  Ã,  Ã, lblNUM.SetText(buffer);
         Ã,  Ã,  Ã, if (GetSaveSlotDescription(index+100,buffer)==0) StrCopy(buffer,"");
         Ã,  Ã,  Ã, txtSAVE.SetText(buffer);
         Ã,  Ã,  Ã, slist=75+((index-GStopsaveitem)*(DEFAULT_FONT_HEIGHT+2));
         Ã,  Ã,  Ã, if (index<9) txtSAVE.SetPosition(12, 0);
         Ã,  Ã,  else txtSAVE.SetPosition(18, 0);
            gSavetext.SetPosition(79, slist);
            gSavetext.Visible = true;                                                            
   }
Ã,  Ã,  if (button == 2 && index>=0) {   //save game                                    
txtSAVE.GetText(buffer);
gSave.Visible = false;                                          
gSavetext.Visible = false;
SaveGameSlot(index+100, buffer);
                                                   }



Ã,  Ã,  if (button == 3){//scroll up
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, gSavetext.Visible = false;
         Ã,  Ã,  Ã,  Ã, lstSAVE.SelectedIndex = -1;
          if (GStopsaveitem<5) GStopsaveitem=0;
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, else GStopsaveitem-=5;
          lstSAVE.TopItem = GStopsaveitem;
                              }

Ã,  Ã,  if (button == 4 && GStopsaveitem<90){ //scroll down
            gSavetext.Visible = false;
            lstSAVE.SelectedIndex = -1;
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  GStopsaveitem+=5;
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  lstSAVE.TopItem = GStopsaveitem;
Ã,  Ã, }


}

if (interface == SAVETEXT){
      int index2;
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  index2 = lstSAVE.SelectedIndex;
Ã,  Ã,  Ã, 
if (button == 0){ //write save name
            txtSAVE.GetText(buffer);Ã,  Ã,  Ã, 
            gSave.Visible = false;
            gSavetext.Visible = false;
                                 SaveGameSlot(index2+100,buffer);
                                 }
Ã,  Ã,  if (IsButtonDown(RIGHT)) gSavetext.Visible = false; //turn off GUI


}

if (interface == LOAD) {
Ã,  Ã,  if (button ==4) gLoad.Visible = false; //cancel
Ã,  Ã,  if (button ==2){ //click on listbox item
            int index3;
            index3 = lstREST.SelectedIndex;
            if (GetSaveSlotDescription(index3 + 100, buffer)==1) { //if saved games exist
            gLoad.Visible = false;
            RestoreGameSlot(index3+100);
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  Ã, }
Ã,  Ã, 
Ã,  Ã,  if (button == 0){ //scroll up
Ã,  Ã,  Ã,  Ã,  Ã, if (GStopsaveitem<5) GStopsaveitem=0;
Ã,  Ã,  Ã,  Ã,  Ã, else GStopsaveitem-=5;
Ã,  Ã,  Ã,  Ã,  Ã, lstREST.TopItem = GStopsaveitem;
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  if (button == 1 && GStopsaveitem<90) { //scroll down
Ã,  Ã,  Ã,  GStopsaveitem+=5;
Ã,  Ã,  Ã,  lstREST.TopItem = GStopsaveitem;
Ã,  Ã,  Ã, 
Ã,  Ã,  }
Ã,  Ã, 
Ã,  Ã, 

Ã,  Ã, 
}


Title: Re: Save Game Issues
Post by: BernieLaraemie on Tue 26/07/2005 08:21:15
That's actually what I had before, and it results in some really weird errors.  The label is always set to 0, it always writes to 1 and clicking on any number in the load list box will load that game.

~~Bernie
Title: Re: Save Game Issues
Post by: strazer on Wed 27/07/2005 07:27:17
Quote from: Gilbot V7000a on Tue 26/07/2005 06:29:35bear in mind that variables declared inside of a function are not initialized

They are, as of AGS v2.7 (http://www.adventuregamestudio.co.uk/tracker.php?action=detail&id=271)
Title: Re: Save Game Issues
Post by: BernieLaraemie on Wed 27/07/2005 07:37:28
Is that why my script isn't working?  I've racked my brain and I'm really not sure what to do with it.

~~Bernie
Title: Re: Save Game Issues
Post by: strazer on Wed 27/07/2005 07:49:42
I'm sure it's unrelated, I just wanted to correct Gilbert's statement.
Title: Re: Save Game Issues
Post by: BernieLaraemie on Thu 28/07/2005 00:15:43
Ah.

Not another mystery solved, then.

~~Bernie
Title: Re: Save Game Issues [SOLVED]
Post by: BernieLaraemie on Fri 29/07/2005 04:38:03
Erm, why is this marked solved?  It hasn't been.

~~Bernie
Title: Re: Save Game Issues (Hasn't been solved)
Post by: TerranRich on Fri 29/07/2005 06:18:34
I saw the word solved and I thought it was solved. Don't be ambiguous! ;) :P
Title: Re: Save Game Issues (Hasn't been solved)
Post by: BernieLaraemie on Fri 29/07/2005 10:00:42
I shall keep that in mind ;)

~~Bernie