Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: HandsFree on Wed 26/09/2012 22:29:35

Title: function call after mouseclick [solved]
Post by: HandsFree on Wed 26/09/2012 22:29:35
I found a lot of posts dealing with something like this, but I'm still not sure what I should do here.  (wrong)
I want to reset some things after a leftclick if it has caused the mouse.mode to change. For instance when you pick something up and the mouse changed from interact to useinv.

I tried
function on_mouse_click(MouseButton button) {
  if (button == eMouseLeft){
    iLastCursor = mouse.Mode;
    ProcessClick(mouse.x, mouse.y, mouse.Mode);
    if (iLastCursor != mouse.Mode) ResetCommands();
  }
}
But the ResetCommands() doesn't happen. Without the condition it doesn't work either.
If I put the ResetCommands() in the interact function it works:

function oOpenDrawer_Interact()
{
  cEgo.AddInventory(iBook);
  cEgo.ActiveInventory = iBook;
  ResetCommands();
}

But of course I like to have it in one place. Is there a way to get it to work in the on_mouse_click function?
thanks
Title: Re: function call after mouseclick
Post by: Khris on Wed 26/09/2012 22:47:22
ProcessClick() is one of those pesky few commands that don't get called until after the current function has finished.
Thus iLastCursor is equivalent to mouse.Mode every time.

Since ProcessClick usually starts some blocking event, you can use repeatedly_execute to call your function:

Code (ags) Select
bool DoAfterPC;

function on_mouse_click(MouseButton button) {
  if (button == eMouseLeft){
    iLastCursor = mouse.Mode;
    DoAfterPC = true;
    ProcessClick(mouse.x, mouse.y, mouse.Mode);
  }
}

// in rep_ex

  // code inside will get called once directly after ProcessClick()
  if (DoAfterPC) {
    DoAfterPC = false;
    // actual code here
    if (iLastCursor != mouse.Mode) ResetCommands();
  }
Title: Re: function call after mouseclick [solved]
Post by: HandsFree on Wed 26/09/2012 23:04:26
Yes, that's it.
thanks