Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: arj0n on Tue 23/02/2021 18:13:54

Title: on_key_press Return doesn't work in globalscript but does work in roomscript [so
Post by: arj0n on Tue 23/02/2021 18:13:54
For some reason I fail to see why this is happening, so I hope someone here can explain this:

The roomscript code (as shown below) is working correctly: ENTER does load game.
(in this case the Global script has no (keycode == eKeyReturn) section in the on_key_press(eKeyCode keycode) function)

But:
The Global script code (as also shown below) is NOT working correctly: ENTER does NOT load the selected game.
(in this case the Room script has no (keycode == eKeyReturn) section in the on_key_press(eKeyCode keycode) function)

Room script:
Code (ags) Select
function on_key_press(eKeyCode keycode)
{
  if (keycode == eKeyReturn)
  {
    if (gRestoreGame.Visible == true)
    {
      if (lstRestoreGamesList.SelectedIndex >= 0)
      {
        RestoreGameSlot(lstRestoreGamesList.SaveGameSlots[lstRestoreGamesList.SelectedIndex]);
      }
    }
  }
}


Global script:
Code (ags) Select
function on_key_press(eKeyCode keycode)
{
...
  else if (keycode == eKeyReturn)
  {
    if (gRestoreGame.Visible == true)
    {
      if (lstRestoreGamesList.SelectedIndex >= 0)
      {
        RestoreGameSlot(lstRestoreGamesList.SaveGameSlots[lstRestoreGamesList.SelectedIndex]);
      }
    }
  }
...
}


EDIT:
darn, this was why:

Code (ags) Select

else if (IsGamePaused() || !IsInterfaceEnabled())
  {
    keycode = 0;
  }
Title: Re: on_key_press Return doesn't work in globalscript but does work in roomscript [so
Post by: eri0o on Tue 23/02/2021 18:21:30
Yeah, asking things here has the magic of helping to think for some reason. Happy it worked :)
Title: Re: on_key_press Return doesn't work in globalscript but does work in roomscript [so
Post by: arj0n on Tue 23/02/2021 18:24:12
True  ;)