Save/Restore GUIs using version 2.7 (SOLVED)

Started by sloppy, Thu 02/02/2006 03:44:19

Previous topic - Next topic

sloppy

The symbol I was getting was always the same one - a "c" with a circle around it.
I've put the string at the beginning of the global script and now everything works. 

That's it!  This save/load GUI is now complete.  Thanks Ashen for all your help and patience!  I really really appreciate it!

This thread went much longer than I thought it would.  Hopefully it'll be helpful to anyone else who wants to make a save/load GUI from scratch using version 2.7.

Ashen

So, wait: Can we finally label this SOLVED?
I know what you're thinking ... Don't think that.

sloppy

Yeah, I'd say so.  The one thing I noticed at this point is that when the 20 slots are full it will overwrite the game at the top of the list.  But if you choose a game that's farther down, it will repeat it.

Maybe I'm just being picky, but I can't figure out why that would happen.

Ashen

Dang, and I thought we were done with this.

That's not being picky, it sounds like a fairly major - at least majorly annoying - bug.
Can you describe exactly what's happening? If you select the top savegame it overwrites OK, but otherwise it creates a new game, over the 20?

One thing to remember: ListBox.FillSaveGameList() sorts chronologically, with the most recent save at the top - so when you overwrite a game, it'll jump to the top of the list. Is this what's happening? If so it's not a bug and, AFAIK, it's unavoidable without manually scripting the array (not using FillSaveGameList() or (savegameindex[..]).
I know what you're thinking ... Don't think that.

sloppy

It's exactly the way you described it.  You've named the saved games from the top 20, 19, 18.  If you then saved the game as 18, it will replace game 20, but there will still be a game 18.  So now 18, 19, 18.

Ashen

I don't know what could be causing that ... It should go:
20
19
18
17
etc

Then, if you overwrite 18:
18
20
19
17
etc

How does the restoring work? Does game 20 still restore to the same point or has it in fact been overwriten?
One possibility is that save_listbox_chris.SelectedIndex is being reset to 0 when gConfirm is switched on. Try declaring an int outside of interface_click, and setting that before you turn on gConfirm, i.e
Code: ags

selected_slot = save_listbox_chris.SelectedIndex;
gConfirm.Visible = true;


Then, for the 'Yes' button:
Code: ags

  if (selected_slot != -1) {
    SaveGameSlot (savegameindex[selected_slot], input);
    gSavegui.Visible=false;
    gConfirm.Visible=false;
    }
I know what you're thinking ... Don't think that.

sloppy

No, it still happens.  And just to make sure , I tried this without using the Confirm GUI, and the same thing happens.

Also, the game name at the top of the list restores fine, but when I restore the same game name lower down the game crashes.

Ashen

This is very annoying. (And I don't suppose it's much fun for you, either ;D)

Can you post the whole code for SAVEGUI, and CONFIRM? (For all buttons - and what button is what). There might be something caused by adding some, then changing it, then adding some more, etc, that's not obvious looking at it in pieces but that fresh eyes could pick out.
I know what you're thinking ... Don't think that.

sloppy

Okay, here it all is.Ã,  And just to let you know, each button's scripting is in its own control function, not in the interface_click function.

gSavegui
save_button = button 0:
Code: ags

int bg_save_idx;

bg_save_idx = save_listbox_chris.ItemCount;
save_textbox_chris.GetText(input);
if (StrComp(input, "")==0) {
Ã,  Display("You must enter a name to save!");
Ã,  return;
Ã,  }
if (save_listbox_chris.SelectedIndex!=-1) save_listbox_chris.GetItemText(save_listbox_chris.SelectedIndex, item);
if (StrComp (input, item) == 0) {
Ã,  Ã,  SaveGameSlot (savegameindex[save_listbox_chris.SelectedIndex], input);
Ã,  gSavegui.Visible=false;
} 

 else if (bg_save_idx<20) { 
Ã,  Ã,  SaveGameSlot(bg_save_idx+1, input);
Ã,  gSavegui.Visible=false;Ã,  
Ã,  }
Ã,  else if (bg_save_idx>=20) {Ã,  Ã, 
 selected_slot = save_listbox_chris.SelectedIndex;
gConfirm.Visible = true;
}
Ã,  else Display ("Select a slot to overwrite.");
 }


gLoadgui
restore_button = button 0:
Code: ags

int bg_restore_idx; 
stringÃ,  bg_restore_buf;
Ã,  Ã, bg_restore_idx= restore_listbox_chris.SelectedIndex;Ã,  Ã, 
 if (bg_restore_idx==-1) {
Ã,  Ã, Display("Please make a selection.");
Ã,  Ã, return;
}
else {
restore_listbox_chris.GetItemText(restore_listbox_chris.SelectedIndex, bg_restore_buf);
RestoreGameSlot(savegameindex[bg_restore_idx]);Ã,  Ã, 
gLoadgui.Visible=false; 
}
}


gConfirm
yes_button = button 1:
Code: ags

if (selected_slot != -1) {
Ã,  Ã,  SaveGameSlot (savegameindex[selected_slot], input);
Ã,  Ã,  gSavegui.Visible=false;
Ã,  Ã,  gConfirm.Visible=false;
Ã,  Ã,  }


All other ints and strings are declared at the beginning of the global script.

Ashen

Well, there's a little problem with the last condition of the Save button:
Code: ags

  else Display ("Select a slot to overwrite.");


That was my mistake - you don't need this else condition.

That's not the major problem, though, just a bit of pointless code. I don't know what the main problem is. That code works perfectly for me, with or without the Confirm GUI, and whether I used selected_slot or save_listbox_chris.SelectedIndex. The one problem I had was trying to reload a game saved with an eariler version of the code (i.e. before I'd added the Load and Confirm GUIs) which will cause a crash (What error message do you get when it crashes, by the way?). The lists and overwriting works great - I honestly can't see why it's not working for you.

Sorry this isn't more help...
I know what you're thinking ... Don't think that.

sloppy

I don't know either.

The error message says:
Error: Restore_game: Global script changed, cannot restore game.

DoorKnobHandle

That error message means that you tried restoring a savegame that was saved with an earlier version of your game.

Go into your compiled-folder and delete all the savegame-files in there. Then restart your game and save/restore. This error message shouldn't come up any longer...

Ashen

#32
That's the error I was talking about.

What dkh said should solve the crash, and starting from fresh might clear up the list bug.

EDIT: To get the name right. Sorry dkh.
I know what you're thinking ... Don't think that.

sloppy

#33
Well it doesn't crash any more.Ã,  It still will repeat a previously saved game.Ã, 

But here's an interesting thing:
It repeats a previos saved game only when I type it in the textbox and the Confirm GUI appears.Ã,  When I highlight a previous game from the listbox and it appears in the textbox and hit save, the Confirm GUI doesn't appear and then it overwrites it exactly as it should.Ã, 

I don't know if that means anything, but I thought it may.

Ashen

#34
That's because overwriting without changing the name is handled by a seperate condition (if (StrComp (input, item) == 0)).

Hang on - I might have misunderstood the problem here.
Do you want it that if you type the name of an existing slot, that slot will be overwritten even if it isn't selected? 'Cause that's totally different to what I was thinking the problem was, and I reckon I know how to solve that (it's not actually a bug, just the way the code is written).
I know what you're thinking ... Don't think that.

sloppy

What I thought should happen is whether typed in or highlighted, and whether the listbox has less that 20 or more than 20, there would never be duplicate named saved games.

Ashen

#36
No, the way it works now is:
1. If you select a slot
save_textbox_chris 'gets' the name of the slot. If you hit 'Save' right away the slot will be overwritten with the same name. If you change the name at all, it counts as a 'new' slot name.

2. If you enter a 'new' slot name
If there are less that 20 existing savegames, a new slot will be created with the name you entered - even if a game with the same name already exists. If there are 20 existing savegames the selected slot is overwritten with the name you entered - even if a game with the same name already exists.
(SelectedIndex defaults to the top slot when the GUI opens - if you haven't been changing this, that would explain why the top game is always overwritten.)

Now, if you want to check all slots against the entered name and overwrite if there's a match, you need to turn these conditions:
Code: ags

if (save_listbox_chris.SelectedIndex!=-1) save_listbox_chris.GetItemText(save_listbox_chris.SelectedIndex, item);
if (StrComp (input, item) == 0) {
    SaveGameSlot (savegameindex[save_listbox_chris.SelectedIndex], input);
  gSavegui.Visible=false;
} 


into a while loop to check input against every ListBox item, not just the selected one:
Code: ags

selected_slot = 0; // You can make a new int for this, if you'd rather
while (selected_slot < bg_save_idx) { // i.e. < number of items
  save_listbox_chris.GetItemText(selected_slot, item);
  if (StrComp (input, item) == 0) {
    SaveGameSlot (savegameindex[selected_slot], input);
    gSavegui.Visible=false;
    return;
  } 
  selected_slot ++;
}

(Not very thoroughly tested, but should work.)
Which will check all existing slots against the entered name. If a match is found, it'll overwrite and stop. If no match is found, it'll go on the the other conditions (save or overwrite with a new name). You'll also need to change else if (bg_save_idx<20) to if (bg_save_idx<20).
I know what you're thinking ... Don't think that.

sloppy

Perfect!  That's exactly the way I wanted it.

I would say we could wrap this one up.  I apologize that it took so long to get it to this point, and again I appreciate all the help.

SMF spam blocked by CleanTalk