"Array index out of bounds" error message with Joe Carl's GUI (SOLVED)

Started by Akril15, Sun 25/05/2008 23:02:13

Previous topic - Next topic

Akril15

I'm using Joe Carl's Save/Restore GUI, and I've saved 31 games successfully with it, but when I tried to save a new game today, I got the "Are you sure you want to overwrite this saved game?" message. I had obviously run out of save game slots, so there was nothing troubling about seeing this message, but when I clicked "Yes", the game crashed and gave me this error message:

QuoteAn internal error has occurred. Please note down the following information. If this problem persists, please contact Chris Jones.
(ACI version 2.72.920)

Error: run_text_script1: error -6 running function 'overwriteSI_btn_Click':
Error: Array index out of bounds (index: 27, bounds: 0..19)
inGlobal script (line 181)

Here's the code for the overwriteSI_btn_Click function:
Code: ags
#sectionstart overwriteSI_btn_Click  // DO NOT EDIT OR REMOVE THIS LINE
function overwriteSI_btn_Click(GUIControl *control, MouseButton button) {
 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="";
gGui0.Visible=true;
return;
} 
p++;  
}
 
}
#sectionend overwriteSI_btn_Click  // DO NOT EDIT OR REMOVE THIS LINE


And this is line 181:
SaveGameSlot(savegameindex[p], guardar.Text);

I tried restarting the game and saving the game again and got the same error message. I've searched the forums for "Array index out of bounds", but the code mentioned in all the posts is somewhat different than the code I'm using, and I'm hesitant to try fixing something I don't entirely understand. For some reason, I've been able to master almost all the basics of AGS, yet GUIs are still beyond my grasp.

GarageGothic

I haven't looked through the entire code, so there may be other problems. But try changing:

Code: ags
while(p<=partidas.ItemCount)


to

Code: ags
while(p<partidas.ItemCount)


and see if it changes anything. The problem is that arrays indexes start at zero rather than one, so the largest array index you can use is arraysize-1.

Edit: Hmm, although seemingly redundant, the "if (partidas.ItemCount>p)" should actually prevent that issue. I can't really spot any other problems since I don't know what the rest of the code looks like. I don't remember when number of saves was increased from 20 to 50.I see you're using version 2.72 - but if you managed to save 31 games that shouldn't be the cause.

Akril15

I tried changing that line, but got the exact same error message when I tried saving the game again.

Here's the entire Save/Restore/Overwrite code, in case it reveals any additional problems:

Code: ags

#sectionstart overwriteSI_btn_Click  // DO NOT EDIT OR REMOVE THIS LINE
function overwriteSI_btn_Click(GUIControl *control, MouseButton button) {
 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="";
gGui0.Visible=true;
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) {
  gOverwrite.Visible=false;
  cerrar.Enabled=true;
  
}
#sectionend overwriteNO_btn_Click  // DO NOT EDIT OR REMOVE THIS LINE

#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==""){
Display("Please enter a name before saving.");
return;
}
int p = 0;
while(p<=partidas.ItemCount){
  if((partidas.ItemCount>p)&&(partidas.Items[p]==guardar.Text)){
gOverwrite.Visible=true;
cerrar.Enabled=false;
return;
} 
p++;  
}

UnPauseGame();  
gSaverestore.Visible=false;
SaveGameSlot(partidas.ItemCount+1, guardar.Text);
  partidas.FillSaveGameList();
  guardar.Text="";
Display("Game saved.");
gGui0.Visible=true;
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) {
  

if(guardar.Text==""){
Display("Please enter a name before saving");
return;
}
int p = 0;
while(p<=partidas.ItemCount){
  if((partidas.ItemCount>p)&&(partidas.Items[p]==guardar.Text)){

gOverwrite.Visible=true;
cerrar.Enabled=false;
gGui0.Visible=true;
return;

} 
p++;  
}

UnPauseGame();  
gSaverestore.Visible=false;
SaveGameSlot(partidas.ItemCount+1, guardar.Text);
  partidas.FillSaveGameList();
  guardar.Text="";
Display("Game saved.");
gGui0.Visible=true;
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) {
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 Display("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) {
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) {
UnPauseGame();
gSaverestore.Visible=false; 
gGui0.Visible=true;
guardar.Text=""; 
  
  
}
#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) {
  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) {
  partidas.ScrollDown();
  
  
}
#sectionend FlechaPartidasDOWN_btn_Click  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart saverestore_Click  // DO NOT EDIT OR REMOVE THIS LINE
function saverestore_Click(GUIControl *control, MouseButton button) {
  btnimage.Animate(23, 5, 3, eRepeat);
  partidas.FillSaveGameList();
  gOptions.Visible=false;
  gSaverestore.Visible=true;
  mouse.UseModeGraphic(eModePointer);
}
#sectionend saverestore_Click  // DO NOT EDIT OR REMOVE THIS LINE

Akril15

Can anyone possibly shed some light on this problem? My game's pretty short, so it's highly unlikely that a player will create 30 saved games, but I'd still like to do something about this.

Gilbert

I'm not quite sure about your problem as I didn't read all of your codes, but as the array savegameindex[] is a pre-2.7 thing, which is obsolete since the move to OO in V2.7x, it may not even work, try to change ALL the savegameindex[blah] to partidas.SaveGameSlots[blah][/b] instead.

Akril15

That little suggestion seems to have completely solved my problem. Thank you very much for your help.

SMF spam blocked by CleanTalk