Save/Load game GUI

Started by Gs92, Wed 03/09/2008 16:33:55

Previous topic - Next topic

Gs92

Ok, so i've started out my second game in ags, and it's a default one, so i've been editing the different GUIs to my liking (too lazy to make my own :P) and the only ones left are the "SaveGameDialog" and "LoadGameDialog", only problem is I can't find them. I see them in the globalscript and all but not among the GUIs.

Is it possible to find and edit these, and if not, how do I script my own save/load game buttons?

Help please! :P

TwinMoon

#1
You can't edit the default ones, but it's very easy to make some yourself:

LOAD GUI:
Make a new gui (I'll call it gLoad in this example) and put a listbox and a button on it. Call the listbox lstSaveGames. Before everytime you put gLoad.Visible = true put the line:
lstSaveGames.FillSaveGameList();
This will fill the listbox with the saved games.

Click on the button, and the events tab (button down-right, the one with the lightning bolt). Doubleclick the onclick. Add the line:
RestoreGameSlot(lstSaveGames.SaveGameSlots[lstSaveGames.SelectedIndex]);
This will restore the game the player selected.


SAVE GUI:
A save gui is a little bit more difficult. You'll need the command SaveGameSlot and a text box.
SaveGameSlot needs to be told what number the saved game is, so you need to be careful not to overwrite any.

What you could do is put a listbox (call it lstSaveGames) on the same GUI (I call it gSave), and every time before you make this gui visible, put:
lstSaveGames.FillSaveGameList();
lstSaveGames.Visible = false;

This listbox won't ever be visible but is only used to keep track of what position to save to.

Make a text box, call it SaveGameName open its events tab, double click the onactivate. Now put:
gSave.Visible = false;
SaveGameSlot(lstSaveGames.ItemCount, SaveGameName.Text);

SaveGameName.Text is what the player typed into the text box.

Hope this helps. Totally untested, but there ya go.
Be advised that there can only be 50 savegames, you might want to script something to prevent the player from saving more than that, otherwise the game will crash. (or something like it)

Khris

Quote from: TwinMoon on Wed 03/09/2008 17:57:16Before everytime you put gLoad.Visible = true put the line:
int index = lstSaveGames.SelectedIndex;
This will fill the listbox with the saved games.

I've never coded my own save/load GUIs, but wouldn't one call lstSaveGames.FillSaveGameList(); to achieve that?

TwinMoon

Whoops! Now where did that line come from, I wonder?
Anyway, corrected it. Thanks.

Gs92

Thanks alot! worked nicely :)

Mantra of Doom

The save dialogue works great for me, but I get an error in the load panel.

In the line:
function lstSaveGames_OnSelectionChange(GUIControl *control)
{
RestoreGameSlot(lstSaveGames.SaveGameSlots[index]);
}

I get an error that says undefined symbol 'index'. I'm new to this so I think I'm probably missing something really basic.

Thanks for the help so far!
"Imitation is the sincerest form of imitation."

Reaper

The variable index is not defined, so the compiler doesn't know what it means.

Tell him by using something like

int index = lstSaveGames.SelectedIndex;

at the beginning of the function. Before you can use a, in this case local variable, you must tell the compiler the type and name of the variable, for example:

int index = 0;

for an integer named index. You can assign an initial value ( = 0 ) in this case, but this is optional.

TwinMoon

Yes. What Reaper said. (Told you it was untested!)
I've edited my original post, in case other people will read it.

SMF spam blocked by CleanTalk