Hello again, people,
Still trying to finish off fine-tuning this SAVE GUI I've been hammering away at lately. I've searched the forums, visited many tutorials and FAQs, but only found them confusing. Finally, after many headaches, I was able to produce something. I am able to save games with it, but a couple things aren't quite right:
a> I can only save about 13 or so save slots (instead of the usual 20) before it starts overwrighting the most recent slot.
b> I would like whatever slot the player highlights to be entered into the textbox, and have that slot be overwritten, but it still only removes the most recent slot regardless of what the player highlights.
Hopefully, someone with more insight than I can point out what I overlooked. Here's my global script:
// ##### SAVEWINDOW #####
if (interface==7) {
SetMouseCursor (6); // Change cursor to Arrow
if (button==0) { // If SAVE button is pressed
index = ListBoxGetNumItems(8,2); // Get number of saves
if (index<20) { // If there are 19 saves or less
GUIOff (7); // Hide SAVEWINDOW
GUIOn(1); // Show ICONBAR
GetTextBoxText(7,3,text); // Get what player entered in
SaveGameSlot(index,text); // Save as what player typed
SetDefaultCursor(); // Change cursor back to default
}
else { // Otherwise
index=ListBoxGetSelected(7,2); // Get highlighted text
GetTextBoxText(7,3,text); // Get what player entered in
GUIOff (7); // Hide SAVEWINDOW
GUIOn(1); // Show ICONBAR
SaveGameSlot(savegameindex[index],text); // Save as highlighted
SetDefaultCursor(); // Change cursor back to default
}
ListBoxSaveGameList(7,2); // Refresh list for SAVEWINDOW
ListBoxSaveGameList(8,2); // Refresh list for RESTOREWINDOW
}
else if (button == 5){ // If Delete button is pressed
index = ListBoxGetSelected(7,2); // Check if something is highlighted
if (index==-1){ // If nothing is highlighted
Display("Please select a saved game or hit Cancel."); // Display this message
}
else{ // Otherwise
DeleteSaveSlot (savegameindex[index]); // Delete what player highlighted
index = ListBoxGetNumItems(7,2); // Get number of saves
ListBoxSaveGameList(7,2); // Refresh list
ListBoxGetSelected(7, 2) == -1; // Lose the highlight
}
}
if (button == 1) { // If Cancel button is pressed
GUIOff(7); // Hide SAVEWINDOW
GUIOn(1); // Show ICONBAR
SetDefaultCursor(); // Change cursor back to default
}
}
If you need more info, please don't hesitate to ask.
Thanks!
Are you calling ListBoxSaveGameList when you turn the GUI on?
Yes, thanks for asking, I am. The problem persists, though.
Okay, I tinkered around with it today and was able to fix a couple things:
- I can now save up to the maximum number of saves (20), as desired.
- Only whatever is highlighted is deleted, instead of the most recent item
However, problem "B" still exists, in which whatever slot the player highlights should be entered into the textbox, and that highlighted slot should in turn be overwritten. But instead, it only saves over the most recent slot regardless of what the player highlights.
I've tried ListBoxGetItemText & SetTextBoxText but neither one seems to produce any kinds of results.
Updated script:
// ##### SAVEWINDOW #####
if (interface==7) {
SetMouseCursor (6); // Change cursor to Arrow
if (button==0) { // If SAVE button is pressed
index = ListBoxGetNumItems(8,2); // Get number of saves
if (index<20) { // If there are 19 saves or less
GUIOff (7); // Hide SAVEWINDOW
GUIOn(1); // Show ICONBAR
GetTextBoxText(7,3,text); // Get what player entered in
SaveGameSlot(index,text); // Save name as what player entered in
SetDefaultCursor(); // Change cursor back to default
}
else { // Otherwise
index=ListBoxGetSelected(7,2); // Get highlighted text
GetTextBoxText(7,3,text); // Get what player entered in
GUIOff (7); // Hide SAVEWINDOW
GUIOn(1); // Show ICONBAR
SaveGameSlot(savegameindex[index],text); // Save name as what was highlighted
SetDefaultCursor(); // Change cursor back to default
}
ListBoxSaveGameList(7,2); // Refresh list for SAVEWINDOW
ListBoxSaveGameList(8,2); // Refresh list for RESTOREWINDOW
ListBoxSaveGameList(9,2); // Refresh list for DELETEWINDOW
}
else if (button == 5){ // If Delete button is pressed
index = ListBoxGetSelected(7,2); // Check if something is highlighted
if (index==-1){ // If nothing is highlighted
Display("Please select a saved game to delete."); // Display this message
}
else{ // Otherwise
DeleteSaveSlot (savegameindex[index]); // Delete what player highlighted
index = ListBoxGetNumItems(7,2); // Get number of saves
ListBoxSaveGameList(7,2); // Refresh list
ListBoxGetSelected(7, 2) == -1; // Lose the highlight
}
ListBoxSaveGameList(7,2); // Refresh list for SAVEWINDOW
ListBoxSaveGameList(8,2); // Refresh list for RESTOREWINDOW
ListBoxSaveGameList(9,2); // Refresh list for DELETEWINDOW
}
if (button == 1) { // If Cancel button is pressed
GUIOff(7); // Hide SAVEWINDOW
GUIOn(1); // Show ICONBAR
SetDefaultCursor(); // Change cursor back to default
}
}
You need to trap interface ==7 and button == 2 for when the player clicks on an item in the list box, and then use ListBoxGetItemText followed by SetTextBoxText to update the text in the text box.
Thanks again for your help! I really do appreciate it. I think I almost got it.
Here's what I added:
if (button==2){ // If listbox is clicked on
ListBoxGetItemText (7,2,ListBoxGetSelected(7,2),text); // Get what player highlighted
SetTextBoxText(7,3,text); // Put highlighted text in textbox
index=ListBoxGetSelected(7,2); // Get highlighted save slot
}
This DOES bring the highlighted text into the textbox, but it still saves the game to a new slot instead of replacing the one that's highlighted. I figured using ListBoxGetSelected would work, but it doesn't, or at least I'm not using it properly. Any more advice?
The way your logic is set up, if there are less than 20 games you will always save a new one rather than replacing an existing one.
What you need to do is, if there are less than 20 games then compare the text in the text box to the text of the selected item in the list box, and if they're the same overwrite the game instead.
Something like this (untested code):
if (index<20) { // If there are 19 saves or less
GUIOff (7); // Hide SAVEWINDOW
GUIOn(1); // Show ICONBAR
GetTextBoxText(7,3,text); // Get what player entered in
if (ListBoxGetSelected(7,2) >= 0) {
string itemtext;
ListBoxGetItemText (7,2,ListBoxGetSelected(7,2), itemtext);
if (StrComp(itemtext, text) == 0) {
index = savegameindex[ListBoxGetSelected(7,2)];
}
}
SaveGameSlot(index,text); // Save name as what player entered in
SetDefaultCursor(); // Change cursor back to default
}
Thanks VERY much for your help. That worked quite nicely :)
Peace!