Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: shaun9991 on Fri 22/04/2022 11:21:42

Title: Double clicking to load a save game
Post by: shaun9991 on Fri 22/04/2022 11:21:42
Hi all,

I have a standard AGS save/load system set up in my game (https://www.adventuregamestudio.co.uk/site/ags/tutorial/gui/2/) - just wondering if it's possible to "double click" on the desired save-game file name in the list box to load it? Rather than clicking it once, then clicking the Load/Restore button.

I hope that makes sense!

Many thanks,
Shaun
Title: Re: Double clicking to load a save game
Post by: Khris on Fri 22/04/2022 12:00:24
Good question, the listbox event says "OnSelectionChanged", so you need to test whether that event fires if the already selected option is clicked a second time. If it does, you can use a timer to detect a double click.
Title: Re: Double clicking to load a save game
Post by: shaun9991 on Fri 22/04/2022 12:01:20
Great idea - thanks Khris! :) I'll see if that works
Title: Re: Double clicking to load a save game
Post by: Khris on Fri 22/04/2022 12:10:56
This works:

Code (ags) Select
int prevIndex = -1;

// called on every game cycle, even when the game is blocked
function repeatedly_execute_always() {
  if (IsTimerExpired(20)) prevIndex = -1;
}

function lstRestoreGamesList_OnSelectionChanged(GUIControl *control)
{
  int index = control.AsListBox.SelectedIndex;
  if (prevIndex != index) {
    prevIndex = index;
    SetTimer(20, 20); // half a second
  }
  else btnRestoreGame_OnClick(btnRestoreGame, eMouseLeft);
}


edit: removed superfluous else if
Title: Re: Double clicking to load a save game
Post by: shaun9991 on Fri 22/04/2022 17:18:16
Thanks so much Khris! It's up and running :)