Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: BerserkerTails on Mon 14/06/2004 06:47:46

Title: Custom Save/Restore Game help!! (Solved! Mods, lock please)
Post by: BerserkerTails on Mon 14/06/2004 06:47:46
Okay, I've been working at this for two hours to no avail... I was hoping someone could help me. I've been trying to make a custom Save/Load GUI for my game, and I'm completely stuck. I'm *TRYING* to follow the tutorial at GAC (http://atticwindow.adventuredevelopers.com/tutorials.php?id=1), and here's my Global Script:

  if (interface == 4) {
    CentreGUI (4);
    GUIOn (4);
      if (button==3) {
      GUIOff (4);}
        else { index=ListBoxGetSelected(4,0);
        RestoreGameSlot(savegameindex[index]);}
     
  if (interface == 5) {
    CentreGUI (5);
    GUIOn (5);
      if (button==2) {
      GUIOff (5);}
      if (button==3) {
        index=ListBoxGetNumItems (5, 4);
        if (index<20) {
          GetTextBoxText (5, 1,text);
          GUIOff (5);
          SaveGameSlot (index+1,text);}
        else {
          index=ListBoxGetSelected (5, 4);
          GetTextBoxText (5, 1,text);
          GUIOff (5);
          SaveGameSlot(savegameindex[index],text); }
       }


The two GUIs in question are set up like this:
  GUI No. 4 (Restore box):
    -Object 0: List Box
    -Object 1: Label
    -Object 2: Button (Restore)
    -Object 3: Button (Cancel)

  GUI No. 5 (Save box):
    -Object 0: Label
    -Object 1: Text Box
    -Object 2: Button (Cancel)
    -Object 3: Button (Save)
    -Object 4: List Box

Now here's what's not working. The GUIs pop up fine, but nothing works with them except the Cancel button on the Restore GUI (GUI 4). Not even the Cancel button on the Save GUI works!! Can someone PLEASE help?!?
Title: Re: Custom Save/Restore Game help!!
Post by: Gilbert on Mon 14/06/2004 06:56:23
Well, since those scripts are in the interface_click() function (I suppose, and they should be there), I don't think the CentreGUI() and GUIOn() lines are necessary (as they should be called when you call up the GUI's already.
For the button not responding part, had you checked the properties of them and are sure that they're set to receive clicks? (Left click set to 'Run script')

Title: Re: Custom Save/Restore Game help!!
Post by: Radiant on Mon 14/06/2004 11:40:13
In addition to what Gilbot said, did you initialize the saved game listings? There's some function that does that, (forget what it's called) use it whenever you turn the relevant GUIs on.
Title: Re: Custom Save/Restore Game help!!
Post by: BerserkerTails on Mon 14/06/2004 19:07:41
Yeah, I have at the start of ther global_script:

string text;
int index;

You know, I think I may have just figured out the problem... PErhpas instead of the GUIOff command, I should use InterfaceOff...

I'll try that when I get home. Thanks for the help though!
Title: Re: Custom Save/Restore Game help!!
Post by: Pumaman on Mon 14/06/2004 21:50:30
If you use the Match Brace feature on that script, you'll see that the entire "if (interface == 5)" block seems to be inside of the "if (interface == 4)" block, so it will never get called (unless it's just a typo in the code you posted, of course).

And yes, make sure you use ListBoxSaveGameList when you turn the GUI on.
Title: Re: Custom Save/Restore Game help!!
Post by: BerserkerTails on Tue 15/06/2004 06:40:46
CJ, you are brilliant! Thank you SO MUCH! It's works now, perfectly! Time to polish up the actual GUIs now...

Oops, another problem... I'm trying to make it so if a save game is selected in the listbox, pressing the Save button will overwrite it. Here's the code I have SO far...

  if (interface == 5) {
    CentreGUI (5);
    GUIOn (5);
      ListBoxSetSelected (5, 4, -1);
      if (button==2) {
      GUIOff (5);}
      if (button==3) {
        index=ListBoxGetNumItems (5, 4);
        if (index<20) {
          ListBoxGetItemText (5,4,ListBoxGetSelected(5, 4),sele);
          if (sele==-1){
          GetTextBoxText (5, 1,text);
          GUIOff (5);
          SaveGameSlot (index+1,text);}
        else {
          ListBoxGetItemText (5,4,ListBoxGetSelected(5,4),text);
          GUIOff (5);
          SaveGameSlot(savegameindex[index],text); }
        else {
          index=ListBoxGetSelected (5, 4);
          GetTextBoxText (5, 1,text);
          GUIOff (5);
          SaveGameSlot(savegameindex[index],text); }
       }


Now I added a string sele; to the top of the Global_int... Now what? The problem is the line with ListBoxGetItemText (5,4,ListBoxGetSelected(5, 4),sele); on it. See, I'm trying to get the code to check whether there is a file selected. If there isn't, I want (sele== -1). But It can't get that... Please help!
Title: Re: Custom Save/Restore Game help!! (Solved hard, easy problem still remains)
Post by: Gilbert on Tue 15/06/2004 11:36:45
Just use ListBoxGetSelected (), and please remove/comment out the part enclosed by /* and */ (they'll reset the GUI's status whenever you click something on it, you only need them WHEN YOU ARE LAUNCHING THE GUI.

  if (interface == 5) {
/* remove this portion
    CentreGUI (5);
    GUIOn (5);
      ListBoxSetSelected (5, 4, -1);
*/
      if (button==2) {
      GUIOff (5);}
      if (button==3) {
        sele = ListBoxGetSelected (5, 4);
        index=ListBoxGetNumItems (5, 4);
        if (index<20) {
          //ListBoxGetItemText (5,4,ListBoxGetSelected(5, 4),sele);
          if (sele==-1){
          GetTextBoxText (5, 1,text);
          GUIOff (5);
          SaveGameSlot (index+1,text);}
        else {
          ListBoxGetItemText (5,4,ListBoxGetSelected(5,4),text);
          GUIOff (5);
          SaveGameSlot(savegameindex[index],text); }
        else {
          index=ListBoxGetSelected (5, 4);
          GetTextBoxText (5, 1,text);
          GUIOff (5);
          SaveGameSlot(savegameindex[index],text); }
       }

I didn't check much, maybe there're some other problems.
Title: Re: Custom Save/Restore Game help!! (Solved hard, easy problem still remains)
Post by: BerserkerTails on Wed 16/06/2004 01:28:46
Still no dice... Error on the line with "sele = ListBoxGetSelected (5, 4);": Cannot assign to string; Use Str* functions instead.

Thanks for the help Gilbot... Just need a bit more...
Title: Re: Custom Save/Restore Game help!! (Solved hard, easy problem still remains)
Post by: Gilbert on Wed 16/06/2004 02:24:55
Because you SHOULD declare sele as int (you used text for string already), it will hold the position of the selected option (-1 if not selected).
Title: Re: Custom Save/Restore Game help!! (Solved hard, easy problem still remains)
Post by: BerserkerTails on Wed 16/06/2004 03:49:49
I did it. After changeing sele to an int, and changing a few other things, it's working perfectly! Now for the easy stuff... Finishing the graphics for the GUIs, and enabling only the pointer cursor for the GUIs. Not the hardest things to do...

Thanks to eveyone who helped! This topic can be locked if any mods are following it's progress,  ;)
Title: Re: Custom Save/Restore Game help!! (Solved! Mods, lock please)
Post by: Gilbert on Wed 16/06/2004 03:53:35
Good to hear it's working. No need to lock, just let it rot. ;)