Hi everybody!
I want to create a list of save games in chronological order.
Now everything works fine until I let the user delete one of the savegames.
Therefore I'd like to know what happens when one of the games is deleted:
as I understand it from my tests, when I have
agssave.001
agssave.002
agssave.003
agssave.004
and I delete agssave.002
then the new order of the savegames is NOT:
agssave.001
agssave.003
agssave.004
but
agssave.001
agssave.004
agssave.003
Is that the way it works? And if so, is there any way of avoiding this reordering of the savegames?
Many thanks in advance.
Stefan
You could add your own timestamp in to the save slot description and strip it off before displaying it to the player, after having used it to sort the games.
What method are you using to display the save game list? The ListBox.FillSaveGameList should automatically order them by date.
Thanks for your replies!
I think now that I have modified my code according to your suggestions I have to change my question:
If I use the standart set of 20 savegames which are managed by the savegamelist[] array and I have a GUI with a list (called lstSavegames) which displays the savegames to the player then what is the correct way to save a game?
I mean, how do I know which slot I have to save it to?
I can't just write
====
SaveGameSlot(lstSavegames.SelectedIndex, "description");
====
because that could overwrite a savegame.
And another question on the same topic:
Also is this the correct code to delete a savegame?
====
DeleteSaveSlot(savegameindex[lstSavegames.SelectedIndex]);
lstSavegames.RemoveItem(lstSavegames.SelectedIndex);
====
I hope you can further help me.
Thanks again,
Stefan.
The savegameindex array translates between the position in the list box and the actual file name.
So to save you'd just do:
SaveGameSlot(savegameindex[lstSavegames.SelectedIndex], "description");
And your code to delete looks good to me -- though rather than RemoveItem, you'd need to do FillSaveGameList to refresh the list, otherwise the savegameindex array won't be updated.
I'm sorry to bother but I still can't get it to work :-[
The "Open the Save GUI scipt" is:
lstSavegames.FillSaveGameList();
gSave.Visible = true;
Of course, when I open the GUI for the first time the listbox is empty because there are no savegames.
Now I have a textbox on my GUI with the following activation function
function boxDescription_Activate(GUIControl *control) {
String buffer = boxDescription.Text;
if (lstSavegames.ItemCount == 0) {
SaveGameSlot(savegameindex[0], buffer);
}
else if (lstSavegames.ItemCount > 0) {
SaveGameSlot(savegameindex[lstSavegames.ItemCount], buffer);
}
Wait(40); // just for testing purposes
lstSavegames.FillSaveGameList();
}
Now I type something into the textbox and hit enter but nothing happens. The list doesn't get updated. Everything is blanc.
So I close the GUI and open it again ... and now I see one entry with the text I typed into the textbox earlier.
However, if I use the textbox again the one slot always gets overwritten.
I never get more than one savegame.
But as I understand the code it should always add one savegame to the end of the list:
If there are no savegames the file gets written to slot "0".
Else if there are savegames the file gets written to slot "lstSavegames.ItemCount". For example if ItemCount = 3 then slots 0, 1, 2 are full in the savegame list. So our new savegame becomes "ItemCount" which is (in this case) 3.
What do I do wrong?
The savegameindex[] array is not populated for save slots that don't exist. Therefore you could do:
if (lstSavegames.ItemCount < 20) {
SaveGameSlot(lstSavegames.ItemCount + 1, buffer);
}
else {
SaveGameSlot(savegameindex[lstSavegames.SelectedIndex], buffer);
}
That will create a new slot if there are less than 20; otherwise it will overwrite the selected one.
Thanks very much Pumaman!
With your help I understood the SaveGameArray and was finally able to fix the problem! :D
Now everything works like a charm.
Thanks again,
Stefan