Double clicking to load a save game

Started by shaun9991, Fri 22/04/2022 11:21:42

Previous topic - Next topic

shaun9991

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
Support Cloak and Dagger Games on Patreon: https://www.patreon.com/user?u=460039

Khris

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.

shaun9991

Great idea - thanks Khris! :) I'll see if that works
Support Cloak and Dagger Games on Patreon: https://www.patreon.com/user?u=460039

Khris

#3
This works:

Code: ags
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

shaun9991

Thanks so much Khris! It's up and running :)
Support Cloak and Dagger Games on Patreon: https://www.patreon.com/user?u=460039

SMF spam blocked by CleanTalk