Mittens 2017 is likely to be in Iceland in July. Check out the thread for details!

Author Topic: Game crashing on custom load GUI if no save games exist *SOLVED*  (Read 193 times)  Share 

This is probably a silly question, but my brain is seriously not working here.  I have custom save and load GUI's for my game, and they work perfectly, except for one bug.

If I make a call to the load game GUI, and there are no save games currently created, the game crashes.  I know I can solve this with a simple 'if' statement, but I can't figure out how to phrase it.

Here is the code I use to call the GUI:
Code: Adventure Game Studio
  1.   if (keycode == eKeyF7) //OPEN LOAD GAME GUI
  2.   {
  3.     lstLoadGames.FillSaveGameList();
  4.     lstLoadGames.SelectedIndex = 0;
  5.     lLoadName.Text = lstLoadGames.Items[lstLoadGames.SelectedIndex];
  6.     gLoadgame.Visible = true;
  7.   }
  8.  

I know its crashing because the index is empty, but the only way I can think to fix it is by creating an auto-save when you start a new game, so you always have a save game.  That is obviously a band-aid fix.

I did do a search to see if I could find the same problem, but I couldn't find one specific to my exact error, which is "ListBox.Items: invalid index specified"

Thanks in advance, and yes, I know once I see the code I will slap myself for not realized how easy the fix is lol.
« Last Edit: 05 Jan 2017, 03:11 by Divon »

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
Re: Game crashing on custom load GUI if no save games exist
« Reply #1 on: 04 Jan 2017, 22:24 »
Hi... Some times you have to search using word just like you used on your topic...

http://www.adventuregamestudio.co.uk/forums/index.php?topic=24096.msg299216#msg299216
There are those who believe that life here began out there...

Snarky

  • Global Moderator
  • Mittens Earl
  • Private Insultant
    • I can help with proof reading
    •  
    • I can help with translating
    •  
Re: Game crashing on custom load GUI if no save games exist
« Reply #2 on: 04 Jan 2017, 22:34 »
Code: Adventure Game Studio
  1.   if (keycode == eKeyF7) //OPEN LOAD GAME GUI
  2.   {
  3.     lstLoadGames.FillSaveGameList();
  4.     if(lstLoadGames.ItemCount > 0)
  5.     {
  6.       lstLoadGames.SelectedIndex = 0;
  7.       lLoadName.Text = lstLoadGames.Items[0]; // You just set it to 0, no need to look it up!
  8.     }
  9.     else
  10.       lLoadName.Text = "";
  11.     gLoadgame.Visible = true;
  12.   }
  13.  

Re: Game crashing on custom load GUI if no save games exist
« Reply #3 on: 05 Jan 2017, 03:10 »
awesome -- thanks guys, it worked like a charm.  I really appreciate it :)