Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Oreclios on Fri 13/09/2013 09:33:11

Title: Can't get 'on_mouse_click' function work in custom inventory [SOLVED]
Post by: Oreclios on Fri 13/09/2013 09:33:11
Hi all!

First of all, sorry if this is a very easy issue. I'm getting started with AGS and I have a problem with my custom inventory window.

I have made an inventory GUI that appears in the bottom of the screen when the mouse coordinate 'y' is greater than some value. That works fine. The problem is that I can't interact with inventory items. I have activated the option 'Override built-in inventory window click handling' and modified the 'on_mouse_click' in the global script to include eMouseLeftInv and eMouseRightInv functions. I want to use the left click to 'interact' and the right click to 'look at' in the inventory window.

Here is my 'on_mouse_click' code:

Code (ags) Select


if (IsGamePaused()==1)
     return;
else if (button == eMouseLeft){
    if (GetLocationType(mouse.x, mouse.y) == eLocationNothing)
        ProcessClick(mouse.x, mouse.y, eModeWalkto);   
    else {
      if (mouse.Mode==eModeUseinv)
        ProcessClick(mouse.x, mouse.y, eModeUseinv);
      else
        ProcessClick(mouse.x, mouse.y, eModeInteract);
    }
}
else if (button == eMouseRight){
    if (mouse.Mode==eModeUseinv)
      mouse.Mode=eModeInteract;
    else
      ProcessClick(mouse.x, mouse.y, eModeLookat); 
}
else if (button == eMouseLeftInv)
    ProcessClick(mouse.x, mouse.y, eModeInteract); 
else if (button == eMouseRightInv)
    ProcessClick(mouse.x, mouse.y, eModeLookat);



Using this code I can't neither look at inventory items using the right mouse click nor interact with them (to select an item) using the left mouse click. I'm pretty sure there is something very simple that I've missed.

Thanks in advance.
Title: Re: Can't get 'on_mouse_click' function work in custom inventory
Post by: Khris on Fri 13/09/2013 12:00:34
ProcessClick() will ignore GUIs.

Use this instead:
Code (ags) Select
  else if (button == eMouseLeftInv)
    inventory[game.inv_activated].RunInteraction(eModeInteract); 
  else if (button == eMouseRightInv)
    inventory[game.inv_activated].RunInteraction(eModeLookat);

(game.inv_activated is the ID of the inventory item that was clicked, inventory[] is a global array pointing to all inv items)

Also note that instead of interacting with the inv item, you probably want to check whether mouse.Mode == eModeUseinv, then run that to allow for using item A on item B, or otherwise use player.ActiveInventory = inventory[game.inv_activated]; to allow the player to pick up items from inventory.
Title: Re: Can't get 'on_mouse_click' function work in custom inventory
Post by: Oreclios on Fri 13/09/2013 13:23:28
Thanks Khris! That worked perfectly! I knew it was something very easy.