Save Game Dialog Issues

Started by BernieLaraemie, Tue 26/07/2005 04:57:31

Previous topic - Next topic

BernieLaraemie

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
~~~~~
"It doesn't matter whether something is true, just that it is believed." -- Jim Morrison
~~~~~
THIS SPACE FOR RENT

Gilbert

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;
Ã,  Ã,  Ã,  
Ã,  Ã,  }
Ã,  Ã,  
Ã,  Ã,  

Ã,  Ã,  
}


BernieLaraemie

:(

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

~~Bernie
~~~~~
"It doesn't matter whether something is true, just that it is believed." -- Jim Morrison
~~~~~
THIS SPACE FOR RENT

Gilbert

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;
Ã,  Ã,  Ã,  
Ã,  Ã,  }
Ã,  Ã,  
Ã,  Ã,  

Ã,  Ã,  
}



BernieLaraemie

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
~~~~~
"It doesn't matter whether something is true, just that it is believed." -- Jim Morrison
~~~~~
THIS SPACE FOR RENT

strazer

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

BernieLaraemie

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
~~~~~
"It doesn't matter whether something is true, just that it is believed." -- Jim Morrison
~~~~~
THIS SPACE FOR RENT

strazer

I'm sure it's unrelated, I just wanted to correct Gilbert's statement.

BernieLaraemie

Ah.

Not another mystery solved, then.

~~Bernie
~~~~~
"It doesn't matter whether something is true, just that it is believed." -- Jim Morrison
~~~~~
THIS SPACE FOR RENT

BernieLaraemie

Erm, why is this marked solved?  It hasn't been.

~~Bernie
~~~~~
"It doesn't matter whether something is true, just that it is believed." -- Jim Morrison
~~~~~
THIS SPACE FOR RENT

TerranRich

I saw the word solved and I thought it was solved. Don't be ambiguous! ;) :P
Status: Trying to come up with some ideas...

BernieLaraemie

~~~~~
"It doesn't matter whether something is true, just that it is believed." -- Jim Morrison
~~~~~
THIS SPACE FOR RENT

SMF spam blocked by CleanTalk