Save/Load screen scripts

Started by Sir Bob, Sat 10/12/2005 00:15:08

Previous topic - Next topic

Sir Bob

I am looking for two scripts, one for loading, and one for saving.

Save-
List Name: savegames_change
Text Box Name: SaveEntry_change
Save Button Name: SaveGame_Click
Delete Button Name: SaveDelete_Click

Load-
List Name: loadlist_Change
Load Button Name: loadgame_Click
Delete Button Name: loaddelete_Click

EDIT:
Well, I thought I got the save game worked out but... I got this error:

"Line 5: Expected ("

With this script:
Code: ags
1   #sectionstart SaveGame_Click  // DO NOT EDIT OR REMOVE THIS LINE
2   function SaveGame_Click(GUIControl *control, MouseButton button) {
3       string savegamename;
4       SaveEntry.GetText(savegamename);
5       SaveGameSlot(savegames_change, "%s");
6   }
7   #sectionend SaveGame_Click  // DO NOT EDIT OR REMOVE THIS LINE

Ashen

#1
"%s" is used to add strings into text (e.g. Display("My name is %s", cEgo.name);) - it'd require another parameter to be used properly (the string to be added - i.e. savegamename in this case) BUT it isn't supported by SaveGameSlot(). Use:

SaveGameSlot(savegames_change, savegamename);

EDIT: Assuming savegame_change is a valid int, and not just the function for the Save game listbox.
I know what you're thinking ... Don't think that.

Sir Bob

savegames is a list.

Error:
"Line 5: Type Mismatch: Cannot convert Listbox* ot int"

Code: ags
1  #sectionstart SaveGame_Click  // DO NOT EDIT OR REMOVE THIS LINE
2  function SaveGame_Click(GUIControl *control, MouseButton button) {
3    string savegamename;
4    SaveEntry.GetText(savegamename);
5    SaveGameSlot(savegames, savegamename);
6  }
7  #sectionend SaveGame_Click  // DO NOT EDIT OR REMOVE THIS LINE


In other words, how do I specify which slot to save in?

Ashen

Whoa, timing - I just thought of that and edited my post.

You need to get the slot number (probably from the savegames Listbox) and pass that. What code have you got in savegames_change?
I know what you're thinking ... Don't think that.

Sir Bob

Code: ags
#sectionstart savegames_change  // DO NOT EDIT OR REMOVE THIS LINE
function savegames_change(GUIControl *control) {
  
  savegames.FillSaveGameList();
}
#sectionend savegames_change  // DO NOT EDIT OR REMOVE THIS LINE

Ashen

That seems a little pointless to me - it won't actually do anything.

There're two things you need, really - how to add a new save game, and how to overwrite a savegame (using the built-in SaveGameList functions is a hell of a lot easier than figuring it out for yourself, but limits you to 20 slots).

To simply add a new slot, something like this should work:
Code: ags

#sectionstart SaveGame_Click  // DO NOT EDIT OR REMOVE THIS LINE
function SaveGame_Click(GUIControl *control, MouseButton button) {
   string savegamename;
   SaveEntry.GetText(savegamename);
   int index = savegames.ItemCount;
   SaveGameSlot(index+1, savegamename);
}
#sectionend SaveGame_Click  // DO NOT EDIT OR REMOVE THIS LINE


For overwriting, you can either make it happed when you click on savegame (i.e. select the game you want to overwrite - best have a confirmation GUI here), or a seperate 'Overwrite' button (again, a confirm GUI might be an idea). In this case you'd want something like:
Code: ags

#sectionstart SaveOverGame_Click  // DO NOT EDIT OR REMOVE THIS LINE
function SaveOverGame_Click(GUIControl *control, MouseButton button) {
   string savegamename;
   SaveEntry.GetText(savegamename);
   int index = savegames.SelectedIndex;
   SaveGameSlot(savegameindex[index], savegamename);
}
#sectionend SaveOverGame_Click  // DO NOT EDIT OR REMOVE THIS LINE

I know what you're thinking ... Don't think that.

Sir Bob

#6
Thanks Ashen, your a really big help! :D

EDIT: Uh oh! The save games won't appear in the list!

Ashen

#7
I don't think that (now deleted) code is particularly relevant - you need to have called savegames.FillSaveGameList(); before you turn the GUI on, to get the list to appear. (Likewise with loadlist.FillSaveGameList(); and the Load GUI.)

If you've done that, and it still doesn't work, I don't know what to suggest. - beyond checking the listbox script names are right (e.g. you're not filling loadlist, but turning the Save GUI on).

EDIT: Another thing: you might want to turn the save GUI off before saving the game (and add a Wait(1); command) - otherwise it'll be saved with the GUI on-screen.
I know what you're thinking ... Don't think that.

Sir Bob

Ok, now, the overwrite wont work.

Code: ags
#sectionstart SaveGame_Click  // DO NOT EDIT OR REMOVE THIS LINE
function SaveGame_Click(GUIControl *control, MouseButton button) {
   gSavescreen.Visible = false;
   gMenu1.Visible = true;
   gMenu1.Centre();
   string savegamename;
   SaveEntry.GetText(savegamename);
   int index = savegames.ItemCount;
   SaveGameSlot(index+1, savegamename);
}
#sectionend SaveGame_Click  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart over_men_Click  // DO NOT EDIT OR REMOVE THIS LINE
function over_men_Click(GUIControl *control, MouseButton button) {
  
  gOverwritemenu.Visible = true;
  gOverwritemenu.Centre();
}
#sectionend over_men_Click  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart SaveOverGame_Click  // DO NOT EDIT OR REMOVE THIS LINE
function SaveOverGame_Click(GUIControl *control, MouseButton button) {
   gMenu1.Visible = true;
   gMenu1.Centre();
   gOverwritemenu.Visible = false;
   gSavescreen.Visible = false;
   string savegamename;
   SaveEntry.GetText(savegamename);
   int index = savegames.SelectedIndex;
   SaveGameSlot(savegameindex[index], savegamename);
}
#sectionend SaveOverGame_Click  // DO NOT EDIT OR REMOVE THIS LINE

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

Ashen

Won't work in what sense?

How have you set it up? (I.e. What buttons/GUIs are used, and what should they do.)
What is/isn't it doing?
I know what you're thinking ... Don't think that.

Sir Bob

Ok, the overwrite prompt comes up, but when I click on the SaveGameOver button then nothing happens, its supposed to overwrite the selected file and close the menus.

Ashen

#11
The code looks OK ...

It's probably just a typo, but: you said SaveGameOver in your post, and it's SaveOverGame in the code - is it possible the function isn't linked to the button properly? (Even if it was just mis-typed, check anyway.)

Try adding some Display("Check"); commands into SaveOverGame_Click, to see if any of it is running, and if so where it stops.
I know what you're thinking ... Don't think that.

Sir Bob

#12
Another question, I want it so when you click on a file on the savegames list, it automatically types it in on SaveEntry textbox.

EDIT: Oh yeah, is there a way to make it so there is just a save button, and if you type in a description (or click on the file, that puts the text in the textbox, which needs the command above) that is already in the list, then it overwrites it?

I thought I had it, but the text doesn't appear!

Code: ags
#sectionstart savegames_change  // DO NOT EDIT OR REMOVE THIS LINE
function SaveEntry_change(GUIControl *control) {
  
  string text;
  savegames.GetItemText(savegames.SelectedIndex, text);
  SaveEntry.SetText("%s");
}
#sectionend savegames_change  // DO NOT EDIT OR REMOVE THIS LINE

Ashen

#13
I refer you to an earlier answer from a similar problem:
Quote from: me"%s" is used to add strings into text (e.g. Display("My name is %s", cEgo.name);) - it'd require another parameter to be used properly (the string to be added...)

So in this case:
Code: ags

  string text;
  savegames.GetItemText(savegames.SelectedIndex, text);
  SaveEntry.SetText(text);


(This is shown in the entry for Label.SetText, but holds true for Textboxes & Buttons - in fact anything that takes a string input, especially if it only allows one parameter (Character.Say() for example.)

Quote
if you type in a description ... that is already in the list, then it overwrites it?
Interesting ... You'd need to compare the text in SaveEntry with each of the Save slot descriptions, and overwrite or create a new slot as needed. Something like (off the top of my head, and not tested):
Code: ags

  int index;
  string savegamename;
  string savegametemp;
  SaveEntry.GetText(savegamename);
  while (index < savegames.ItemCount) {
    GetSaveSlotDescription(savegameindex[index], savegametemp);
    if (StrCaseComp(savegamename, savegametemp) == 0) {
      SaveGameSlot(savegameindex[index], savegamename);
      return;
      // Match found, save over it, and stop running script.
    }
    index ++; // Not a match, try next slot
  }
  SaveGameSlot (index+1, savegamename); // If no match was found, create new slot

     
NOTE: As I said, not tested, and since it wasn't written in AGS, some of the commands might be misspelt.
I know what you're thinking ... Don't think that.

Sir Bob

#14
Okay, The first script (to make the text appear in the input box) didnt work, the text still doesnt appear. which object do I put the script on? the listbox or the textbox?

The second one worked! Yay!

EDIT: Oops, the function was different from the sectionstart/end. The 1st and second ones work now!

But, when I restore, the game opens up the menu that was saved on earlier, how do I make it so that when they restore they can start playing immedietly.

Also, I want it so that if they clicked save and there is no text in the box, then it doesnt save a game.

Ashen

#15
Where is it - which GUI control is it linked to?

Looking at exactly what you posted, it's run in SaveEntry_change - according to the first post, SaveEntry is the textbox, and you probably want it to be in the Listbox function (savegames_change, as far as I can make out - which the sectionstart/end tags in the code you posted mention), so the text is updated when the selected item changes. (Now, it could be that the function is just called SaveEntry_change, but is run by the Listbox. In which case I don't know what the problem is, as the code works fine for me.)

EDIT after Sir Bob's edit:
So you caught the problem? Cool.

Quote from: Me, a few posts backAnother thing: you might want to turn the save GUI off before saving the game (and add a Wait(1); command) - otherwise it'll be saved with the GUI on-screen.

QuoteI want it so that if they clicked save and there is no text in the box, then it doesnt save a game.

Just check the contents of the savegamename string (after you've got the Textbox text) with StrComp(). If it's empty, display a message telling the player to enter a name, and quit the script. If there is a name, let it save.
I know what you're thinking ... Don't think that.

SMF spam blocked by CleanTalk