GUI & MODULE: Simple Save & Load 1.0

Started by Ubel, Thu 28/12/2006 14:06:14

Previous topic - Next topic

Ghostlady

I can only restore back into the game, the last 20 saves.  It I select save 21 or any save greater than the 20th save, I get this message.

Error: Error running function 'restoregame_Click'
Error: Array index out of bounds(index 21, bounds:0..19)

This is the area in the script the error is pointing to.  Anyone see where the problem is?

function restoregame_Click(GUIControl *control, MouseButton button) {
aSound11.Play();
if(partidas.ItemCount!=0){ 
int index = partidas.SelectedIndex;
RestoreGameSlot(savegameindex[index]);
  partidas.FillSaveGameList();
  savegame.Enabled=true;
  guardar.Enabled=true;
  cerrar.Enabled=true;
  SetGameOption(OPT_WHENGUIDISABLED, 2);
  }else {
  gSavemsg.Visible=true;
  savemsglbl.TextColor = 65296;
  savemsglbl.Text = ("There is no game to load");
  Wait(80);
  gSavemsg.Visible=false; }
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven Plantation
Haunting at Cliffhouse

Dualnames

I'm not sure, but it appears the error comes on line RestoreGameSlot.
Whether the savegameindex array is defined as:
Code: ags

int savegameindex[21];

And therefore it crashes on 21, or it's some old array i don't recall. So either replace the RestoreGameSlot with what i have below or increase the array size.
Code: ags

int savegameindex[50];

Code: ags

function restoregame_Click(GUIControl *control, MouseButton button) 
{
 aSound11.Play();
  
  if(partidas.ItemCount!=0)
  {  
    int index = partidas.SelectedIndex;

    RestoreGameSlot(partidas.SaveGameSlots[[index]);

    partidas.FillSaveGameList();
    savegame.Enabled=true;
    guardar.Enabled=true;
    cerrar.Enabled=true;
    SetGameOption(OPT_WHENGUIDISABLED, 2);
  }

  else 
  {
    gSavemsg.Visible=true;
    savemsglbl.TextColor = 65296;
    savemsglbl.Text = ("There is no game to load");
    Wait(80);
    gSavemsg.Visible=false;
  }

}
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Ghostlady

I don't see where a "savegameindex' is being defined or initialized.  When I tried to add one, I got an error.  Here is the code from the globabl script.

Code: ags
#sectionstart partidas_SelectionChanged  // DO NOT EDIT OR REMOVE THIS LINE
function partidas_SelectionChanged(GUIControl *control) {
  guardar.Text=partidas.Items[partidas.SelectedIndex];   
}
#sectionend partidas_SelectionChanged  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart guardar_Activate  // DO NOT EDIT OR REMOVE THIS LINE
function guardar_Activate(GUIControl *control) {
if(guardar.Text==""){
   gSavemsg.Visible=true;
   savemsglbl.TextColor = 65296;
   savemsglbl.Text = ("Please enter a name before saving");
//Display("Please enter a name before saving");
return;
}
int p = 0;
while(p<=partidas.ItemCount){
  if((partidas.ItemCount>p)&&(partidas.Items[p]==guardar.Text)){
//Display("The game will be overwritten");
     gOverwrite.Visible=true;
     cerrar.Enabled=false;
     gSavemsg.Visible=false;
return;
} 
p++;  
}

UnPauseGame();  
gSaverestore.Visible=false;
SaveGameSlot(partidas.ItemCount+1, guardar.Text);
  partidas.FillSaveGameList();
  guardar.Text="";
  gSavemsg.Visible=true;
  savemsglbl.TextColor = 65296;
  savemsglbl.Text = ("Game Saved");
  Wait(80);
  gSavemsg.Visible=false;
//Display("Game saved"); 
  mouse.UseDefaultGraphic();
return;
}
#sectionend guardar_Activate  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart savegame_Click  // DO NOT EDIT OR REMOVE THIS LINE
function savegame_Click(GUIControl *control, MouseButton button) {
aSound11.Play();
if(guardar.Text==""){
   gSavemsg.Visible=true;
   savemsglbl.TextColor = 65296;
   savemsglbl.Text = ("Please enter a name before saving");
//Display("Please enter a name before saving");
return;
}
int p = 0;
while(p<=partidas.ItemCount){
  if((partidas.ItemCount>p)&&(partidas.Items[p]==guardar.Text)){
//Display("The game will be overwritten");
     gOverwrite.Visible=true;
     cerrar.Enabled=false;
return;
} 
p++;  
}

UnPauseGame();  
gSaverestore.Visible=false;
SaveGameSlot(partidas.ItemCount+1, guardar.Text);
  partidas.FillSaveGameList();
  guardar.Text="";
  gSavemsg.Visible=true;
  savemsglbl.TextColor = 65296;
  savemsglbl.Text = ("Game Saved");
  Wait(80);
  gSavemsg.Visible=false;
//Display("Game saved");
  mouse.UseDefaultGraphic(); 
  UnPauseAudio();
return;
}
#sectionend savegame_Click  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart restoregame_Click  // DO NOT EDIT OR REMOVE THIS LINE
function restoregame_Click(GUIControl *control, MouseButton button) {
aSound11.Play();
if(partidas.ItemCount!=0){  
int index = partidas.SelectedIndex;
RestoreGameSlot(savegameindex[index]);
  partidas.FillSaveGameList();
  savegame.Enabled=true;
  guardar.Enabled=true;
  cerrar.Enabled=true;
  SetGameOption(OPT_WHENGUIDISABLED, 2);
  }else {
  gSavemsg.Visible=true;
  savemsglbl.TextColor = 65296;
  savemsglbl.Text = ("There is no game to load");
  Wait(80);
  gSavemsg.Visible=false; }
//Display("There is no game to load"); 
}
#sectionend restoregame_Click  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart borrar_Click  // DO NOT EDIT OR REMOVE THIS LINE
function borrar_Click(GUIControl *control, MouseButton button) {
aSound11.Play();
if(partidas.ItemCount>=1){
int index = partidas.SelectedIndex;  
  DeleteSaveSlot(savegameindex[index]);
  partidas.FillSaveGameList();
  }
}
#sectionend borrar_Click  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart cerrar_Click  // DO NOT EDIT OR REMOVE THIS LINE
function cerrar_Click(GUIControl *control, MouseButton button) {
aSound11.Play();
UnPauseGame();
gSaverestore.Visible=false; 
guardar.Text=""; 
mouse.UseDefaultGraphic();
UnPauseAudio();
}
#sectionend cerrar_Click  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart FlechaPartidasUP_btn_Click  // DO NOT EDIT OR REMOVE THIS LINE
function FlechaPartidasUP_btn_Click(GUIControl *control, MouseButton button) {
  aSound11.Play();
  partidas.ScrollUp();
}
#sectionend FlechaPartidasUP_btn_Click  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart FlechaPartidasDOWN_btn_Click  // DO NOT EDIT OR REMOVE THIS LINE
function FlechaPartidasDOWN_btn_Click(GUIControl *control, MouseButton button) {
  aSound11.Play();
  partidas.ScrollDown();
}
#sectionend FlechaPartidasDOWN_btn_Click  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart overwriteSI_btn_Click  // DO NOT EDIT OR REMOVE THIS LINE
function overwriteSI_btn_Click(GUIControl *control, MouseButton button) {
 aSound11.Play();
 int p = 0;
while(p<=partidas.ItemCount){
  if((partidas.ItemCount>p)&&(partidas.Items[p]==guardar.Text)){
UnPauseGame();
gOverwrite.Visible=false;
gSaverestore.Visible=false;
cerrar.Enabled=true;
SaveGameSlot(savegameindex[p], guardar.Text);
partidas.FillSaveGameList();
guardar.Text="";
gSavemsg.Visible=true;
savemsglbl.TextColor = 65296;
savemsglbl.Text = ("Game Overwritten");
Wait(80);
gSavemsg.Visible=false;
//Display("Game overwritten");
UnPauseAudio();
return;
} 
p++;  
}
}
#sectionend overwriteSI_btn_Click  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart overwriteNO_btn_Click  // DO NOT EDIT OR REMOVE THIS LINE
function overwriteNO_btn_Click(GUIControl *control, MouseButton button) {
  aSound11.Play();
  gOverwrite.Visible=false;
  cerrar.Enabled=true;
}
#sectionend overwriteNO_btn_Click  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart gSavemsg_Click  // DO NOT EDIT OR REMOVE THIS LINE
function gSavemsg_Click(GUIControl *control, MouseButton button) {
if (mouse.IsButtonDown(eMouseLeft)) {
    gSavemsg.Visible=false; }
}
#sectionend gSavemsg_Click  // DO NOT EDIT OR REMOVE THIS LINE

My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven Plantation
Haunting at Cliffhouse

Dualnames

Replace savegameindex[] with partidas.SaveGameSlots[] then?

That's my guess, here.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Ghostlady

Are you saying replace

RestoreGameSlot(savegameindex[index]);

with

RestoreGameSlot(partidas.SaveGameSlots[index]);

My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven Plantation
Haunting at Cliffhouse

SMF spam blocked by CleanTalk