Custom Save/Restore GUI in AGS

This is a public forum, where you can find out everything you wanted to know about making games. Please don't use this forum as a place to recruit new members.

Moderators: adeyke, VampD3, eriqchang, Angelus3K

Post Reply
Message
Author
Kurdt
Hero For Hire
Posts: 1081
Joined: Fri Jan 11, 2002 5:58 am
Location: Texas
Contact:

Custom Save/Restore GUI in AGS

#1 Post by Kurdt » Tue Aug 01, 2006 6:51 pm

I've looked everywhere trying to understand how to make one of these. The help file is nonexistent on this part, and the AGS-heads at the forums are no help either. I've found two threads on the subject at BIGBLUECUP, but after a week of trying to decipher them and coming up empty, I'm deferring to those who've done it before.

So what the hell do I do??? I want GUIs that allow you to Save, Restore, and Delete your save games, and if possible tell you when you've reached the limit of Saves you can have. I've found the ListBox.FillSaveGameList(); command, but I don't know how or where in the code to execute it. HELP!!! :\

Pidgeot
Defense Minister Status
Posts: 736
Joined: Tue Sep 17, 2002 2:54 pm
Location: Kolding, Denmark
Contact:

#2 Post by Pidgeot » Tue Aug 01, 2006 7:24 pm

A quick search turned up this page: http://atticwindow.adventuredevelopers. ... estore.php

Not sure if it helps you further or if you've already seen it, but hopefully it can help you a bit further, even if it isn't too verbose.

Alliance
Knight Status
Posts: 429
Joined: Wed Jul 21, 2004 5:04 pm
Location: Behind you!
Contact:

#3 Post by Alliance » Tue Aug 01, 2006 7:27 pm

Here you go:

Add this to your global script, near the beginning.
string text;
int index;

function Save() {
 SetMouseCursor(6);
 SetTextBoxText(SAVE,1,""); // Clear Text box
 ListBoxSaveGameList(SAVE,3); // Fill List Box with saved games
 index = ListBoxGetNumItems(SAVE,3); // Count how many saved games there are          
 if (index > 19) // If saved games 20 (maximum)
   DisplayMessage(990); // Display warning
 index = 0;
 InterfaceOn(SAVE); // Bring Save interface on    
}

function Load() {
SetMouseCursor(6);
ListBoxSaveGameList(LOAD,0); // Fill List box with saved games  
InterfaceOn(LOAD); // Bring restore Interface on
}
and then, add this to your interface:
 if (interface == SAVE) { // if save interface
   if (button == 3) {
     ListBoxGetItemText(SAVE, 3, ListBoxGetSelected(SAVE, 3), text);
     SetTextBoxText(SAVE, 1, text);
     index = 21;
   }
   if (button == 1 || button == 5) {
     GetTextBoxText(SAVE,1,text); // Get the typed text
     if (StrCaseComp(text, "") != 0) { // If text not empty
       InterfaceOff(SAVE); // Close interface
       SetDefaultCursor();
       if (index < 20) { // if less than 20
         index = ListBoxGetNumItems(SAVE,3);
         SaveGameSlot(index+1,text); // Save game (text as description)
       }
       else { // if saved games are 20
         index = ListBoxGetSelected(SAVE,3); // Get the selected save game
         SaveGameSlot(savegameindex[index],text);  // Overwrite the selected game
       }
     }
   }
   if (button == 4) {
     InterfaceOff(SAVE); // if cancel is pressed close interface
     InterfaceOn(ICONBAR);
     SetDefaultCursor();
   }
 }

 if (interface == LOAD) {
   if (button == 1) { // if cancel is pressed
     InterfaceOff(LOAD);        // Close interface
     SetDefaultCursor();
   }
   else if (button == 3) {
     index = ListBoxGetSelected(LOAD,0); // else get the selected game
     RestoreGameSlot(savegameindex[index]); // restore the game
   }
 }
You'll also need to create 2 GUIS titled "LOAD" and "SAVE", and set up a text box, a list box and some buttons. Just match all the numbers up accordingly, seeing as I merely just posted the scripts from my game.

Kurdt
Hero For Hire
Posts: 1081
Joined: Fri Jan 11, 2002 5:58 am
Location: Texas
Contact:

#4 Post by Kurdt » Tue Aug 01, 2006 7:52 pm

Could you do me a quick favor and tell me which pieces of code are defined by me? For example, do I really type in "string text" or do I type in "string mygamesavelist" or something like that?

EDIT: Do you have an update on the code for AGS 2.71? A lot of stuff is different with it now. I'm doing my best to convert it all, but I'd like to make sure I'm doing the right thing.

Alliance
Knight Status
Posts: 429
Joined: Wed Jul 21, 2004 5:04 pm
Location: Behind you!
Contact:

#5 Post by Alliance » Tue Aug 01, 2006 8:08 pm

Well, my best advice is to look for the "Reality on the Norm" template on Google. If you can't find it, I'll upload it somewhere and give you the link, seeing as it has the scripts and everything you need.
EDIT: I'll retype my script for you in the meantime, but you're going to have to fill me in on your GUI names, your label and button numbers, etc.

Kurdt
Hero For Hire
Posts: 1081
Joined: Fri Jan 11, 2002 5:58 am
Location: Texas
Contact:

#6 Post by Kurdt » Tue Aug 01, 2006 8:12 pm

I'm just trying to comprehend what all the code means, is all. Separate what's just made up and what's the command itself, y'know? Just throwing a bunch of code at me is slowly beginning to hurt my brain in a not good way, heheh.

Kurdt
Hero For Hire
Posts: 1081
Joined: Fri Jan 11, 2002 5:58 am
Location: Texas
Contact:

#7 Post by Kurdt » Tue Aug 01, 2006 11:49 pm

ALL RIIIIGHT! After much beating my head over my keyboard, I got the Save GUI to function properly!!!!!! w00t! It currently saves a game! Of course, it's yet to be able to delete savegames and I'm not sure if the "Savegame directory is full" scenario works or not, but all in its time!

Now, I need to find out exactly how to get it to replace the save if it's the same name. I've got two saves named "crazymans" and that's hella confusing.

Here's my code, in all its AGS 2.71 glory!

Where Control is my Control Panel GUI, Savegame is my Save GUI, SaveList is my Save Game List Box, SaveText is my Save Game Text Box, and Iconbar is my Icon Bar:
int saves;

#sectionstart SaveButton_Click//SAVE BUTTON IN THE CONTROL PANEL GUI
function SaveButton_Click(GUIControl *control, MouseButton button)
{gControl.Visible = false;
gSavegame.Centre();
gSavegame.Visible = true;
saves = (SaveList.ItemCount);
if (saves > 19) {
 DisplayMessage(990);
 }
}
#sectionend SaveButton_Click//SAVE BUTTON IN THE CONTROL PANEL GUI

#sectionstart CancelSaveButton_Click  // DO NOT EDIT OR REMOVE THIS LINE
function CancelSaveButton_Click(GUIControl *control, MouseButton button) {
gSavegame.Visible = false;
gIconbar.Visible = true;  
}
#sectionend CancelSaveButton_Click  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart SaveList_SelectionChanged  // DO NOT EDIT OR REMOVE THIS LINE
function SaveList_SelectionChanged(GUIControl *control) {
SaveList.FillSaveGameList();  
}
#sectionend SaveList_SelectionChanged  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart SaveText_Activate  // DO NOT EDIT OR REMOVE THIS LINE
function SaveText_Activate(GUIControl *control) {

}
#sectionend SaveText_Activate  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart SavegameButton_Click  // DO NOT EDIT OR REMOVE THIS LINE
function SavegameButton_Click(GUIControl *control, MouseButton button) {
SaveGameSlot(saves, SaveText.Text);
String input = SaveText.Text;
saves = (SaveList.ItemCount);
SaveList.AddItem(input);
gSavegame.Visible = false;
gIconbar.Visible = true;
}
#sectionend SavegameButton_Click  // DO NOT EDIT OR REMOVE THIS LINE
I kept thinking that, since it's an object-based script now, I just have to create what happens when those objects are activated, and then it became a matter of figuring out which commands suited what I wanted to happen. I've still got light years to go before I sleep, but the fact that it's functional is amazing right now.

Kurdt
Hero For Hire
Posts: 1081
Joined: Fri Jan 11, 2002 5:58 am
Location: Texas
Contact:

#8 Post by Kurdt » Sat Aug 05, 2006 5:57 pm

All right, false alarm. The damn Restore list won't show up! I typed in RestoreList.FillSaveGameList(); which is supposed to take care of that. What the hell gives???

pass
Royal Servant Status
Posts: 129
Joined: Wed Mar 22, 2006 8:38 pm
Location: Israel

#9 Post by pass » Sat Aug 05, 2006 8:46 pm

Umm... This might sound silly, but... Do you have any saved games? of the updated version of the game? (i.e. try saving and immediately loading).

Kurdt
Hero For Hire
Posts: 1081
Joined: Fri Jan 11, 2002 5:58 am
Location: Texas
Contact:

#10 Post by Kurdt » Sun Aug 06, 2006 4:00 pm

That's all I do, save and then try to load. I don't think it keeps permanent saves unless you actually compile it like you're going to release it.

But yeah, I save and then try to load and the damn screen's not there.

Right now, I'm trying to get the GUI to work where if you save a game with the same name as another savegame that it'll replace that save (in the typical Sierra fashion). This is what I've got:
#sectionstart SavegameButton_Click  // DO NOT EDIT OR REMOVE THIS LINE
function SavegameButton_Click(GUIControl *control, MouseButton button) {
saves = (SaveList.ItemCount);
String input = SaveText.Text;
String item = SaveList.Items[SaveList.SelectedIndex];
if (input.CompareTo(item) == 0) { // i.e. strings match
SaveGameSlot (SaveList.SelectedIndex, SaveText.Text);
}
else {
SaveGameSlot(saves, SaveText.Text);
SaveList.AddItem(input);
}
gSavegame.Visible = false;
gIconbar.Visible = true;
}
#sectionend SavegameButton_Click  // DO NOT EDIT OR REMOVE THIS LINE
Unfortunately, when I try to run that code it just tells me that ListBox.Items has an "invalid index specified." I've tried moving it around but I don't know what to do on this one.

Alliance
Knight Status
Posts: 429
Joined: Wed Jul 21, 2004 5:04 pm
Location: Behind you!
Contact:

#11 Post by Alliance » Sun Aug 06, 2006 5:23 pm

Try maybe changing the number to the number of the list box?

Broomie
The Enigma
Posts: 2601
Joined: Thu Jan 02, 2003 1:00 am
Location: UK

#12 Post by Broomie » Sun Aug 06, 2006 8:00 pm

Kurdt, read the tutorial. OMG how can you not know this, you n00b? I'm not going to help you.</agsforums> :p

Kurdt
Hero For Hire
Posts: 1081
Joined: Fri Jan 11, 2002 5:58 am
Location: Texas
Contact:

#13 Post by Kurdt » Sun Aug 06, 2006 10:43 pm

Which number is it that I'm changing? I didn't see a place where there was an actual number indicating the index.

I'm going to pour over a thread that's been helping me again and see if I can nab the problem once more. I'll report back when I'm done.

And Broomie, *IA language* my *IA language*.

Post Reply