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:
if (keycode == eKeyF7) //OPEN LOAD GAME GUI
{
lstLoadGames.FillSaveGameList();
lstLoadGames.SelectedIndex = 0;
lLoadName.Text = lstLoadGames.Items[lstLoadGames.SelectedIndex];
gLoadgame.Visible = true;
}
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.
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
if (keycode == eKeyF7) //OPEN LOAD GAME GUI
{
lstLoadGames.FillSaveGameList();
if(lstLoadGames.ItemCount > 0)
{
lstLoadGames.SelectedIndex = 0;
lLoadName.Text = lstLoadGames.Items[0]; // You just set it to 0, no need to look it up!
}
else
lLoadName.Text = "";
gLoadgame.Visible = true;
}
awesome -- thanks guys, it worked like a charm. I really appreciate it :)