Open a confirmation GUI when overwriting saved games. [SOLVED]

Started by RetroJay, Wed 21/03/2012 02:51:52

Previous topic - Next topic

RetroJay

Hi all good peeps.

I have all of my Quit, Save and Load GUI's working just fine.

However.
What I want is for a "Do you want to overwrite this saved game?" GUI to appear if there is already a saved game with that name.
I have done pretty much the same with a delete confirmation GUI and had no probs but this has me stumped.

The code bellow is linked to my Save button on the Save GUI.
What I would like to know is.
At what point would I open the confirmation GUI (I thought just after "// If so, overwrite the selected save game").
Also what script do I need to link to the confirmation GUI's  "Yes" button to get this to work?
I nearly had it working once but then it all went even more pear shaped than your average pear.

EDIT:
The script bellow, with the help of Khris, works just how I wanted it to now. :)
Here it is. ;)

As it says bellow. Put this at top of Global Script.
Code: ags

// top of global script
int temp_savegame_index;
String temp_savename;

------------------------------------------------------------
This I put into the Save button on the Save GUI
Code: ags

function btnConfirmSave_Click(GUIControl *control, MouseButton button) {

// Player pushed Save button on Save GUI  
  int totalSaves = lstSaveGames.ItemCount; //number of saves on list
  String saveName = txtSaveNames.Text; //holds value of txtSaveName
 
// Check for a save name. If none, tell them.  Else, go on.
  if (saveName == "") 
  {
    Display("Please enter a name for your saved game.");
    return;
  }
  
// If there is no saved games yet, just save it.
  if (lstSaveGames.SelectedIndex == -1)
  {
    gSavegame.Visible = false;
    mouse.Mode = eModeInteract;
    mouse.SetBounds(0,0,0,0);
    SaveGameSlot(totalSaves+1, saveName);
    Wait(20);
    Display ("Game saved successfully.");
  }
  
  else
  {
    int checkSave = 0; //runs through the list and checks for double entries
    while (checkSave != totalSaves)
    {
      if (saveName == lstSaveGames.Items[checkSave]) // one matches, so overwrite it.
      {
        // If so, overwrite the selected save game
        temp_savegame_index = savegameindex[checkSave];
        temp_savename = saveName;
        mouse.SetBounds(94, 105, 225, 134);
        gOverwrite.Visible = true;
        return;
      }
      checkSave++;
    }
    
    // There is no match, just save to a new slot.
    if (totalSaves < 10)
    {
      mouse.Mode = eModeInteract;
      mouse.SetBounds(0,0,0,0);
      gSavegame.Visible = false;
      SaveGameSlot(totalSaves+1, saveName);
      Wait(20);
      Display ("Game saved successfully.");
    }
    
    else
    {
      Display("The maximum number of saved games has been reached; overwrite or delete some old ones.");
    }
  }
}

---------------------------------------------------------------------------
This I put into the Yes Button on the confirmation GUI.
Code: ags

function btnOverwrite_Yes_Click(GUIControl *control, MouseButton button) {

// If confirmation GUI's Yes button is clicked:
  SaveGameSlot(temp_savegame_index, temp_savename);
  gOverwrite.Visible = false;
  gSavegame.Visible = false;
  mouse.Mode = eModeInteract;
  mouse.SetBounds(0, 0, 0, 0);
  Wait(20);
  Display ("Game saved successfully.");
}


EDIT:
I cleaned the script up a bit. Hope it's easier to read now.

Many thanks.
Jay.

Khris

There's no easy way to pause a script function and wait for a GUI click.
In Object-oriented scripting, you're supposed to code discrete chunks that work more or less independent of each other by exchanging information.

What you need to do, in pseudo code:

-if a savegame by that name exists, store savegameindex[checkSave], saveName in global variables, open the confirmation GUI, then exit the function

-the confirmation GUI in turn simply gets turned invisible upon canceling the action, and confirming the overwriting will use the global variables to continue where the savegame function left off.

Thus:
Code: ags
// top of global script
int temp_savegame_index;
String temp_savename;

      // inside function:
      if (saveName == lstSaveGames.Items[checkSave]) // one matches, so overwrite it.
      {
        // If so, overwrite the selected save game
        temp_savegame_index = savegameindex[checkSave];
        temp_savename = saveName;
        mouse.Mode = eModeInteract;
        mouse.SetBounds(0,0,0,0);
        gSavegame.Visible = false;
        gConfirmOverwriteSavegame.Visible = true;
        return;
      }
      checkSave++;

// if GUI's confirmation button is clicked:
  SaveGameSlot(temp_savegame_index, temp_savename);
  Wait(20);
  Display ("Game saved successfully.");

RetroJay

Hi Khris.

Ah ha!
I see it all now... some of it. (Damn I was close, just not close enough.)

Works wonderfully. :)

I have edited my top post to mirror these changes, just incase this can help anyone else.

Many Thanks Khris.
Jay.

SMF spam blocked by CleanTalk