Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: m0rph84 on Thu 27/04/2017 16:12:07

Title: Close Inventory after item selected
Post by: m0rph84 on Thu 27/04/2017 16:12:07
Hello,
I'm trying to close the inventory after an inventory item has been selected.
This is my left click function:

Code (ags) Select

function on_mouse_click(MouseButton button) {
  // called when a mouse button is clicked. button is either LEFT or RIGHT
  if (IsGamePaused() == 1) {
    // Game is paused, so do nothing (ie. don't allow mouse click)
  }
  else if (button == eMouseLeft) {
    if (cRicca.ActiveInventory!=null)
    {
      ProcessClickSpecial(mouse.x, mouse.y, eModeUseinv, eModeWalkto);
      gInventory.Visible = false;
    }
    else ProcessClickSpecial(mouse.x, mouse.y, eModeInteract, eModeWalkto);
    gInventory.Visible = false;
    //Room.ProcessClick(mouse.x, mouse.y, mouse.Mode );
  }


I think the problem is that once the left click happen there is no item selected until the next game loop.
In fact a second left click, after the item has been selected, close the inventory.
The problem is that I don't know how to fix that ???

I also tried something like this in repeatedly_execute_always()

Code (ags) Select

if(mouse.click(emouseleft) == true && cRicca.ActiveInventory != null)
{
    gInventory.visible = false;
}


But it crashes badly the games few seconds after launch(as I thought)

Thanks in advance.
Title: Re: Close Inventory after item selected
Post by: Khris on Thu 27/04/2017 16:43:06
You can try this:
function on_event (EventType event, int data) {
  if (event == eEventGUIMouseUp && data == gInventory.ID) { // mouse was released over inv GUI
    if (player.ActiveIntentory != null) gInventory.Visible = false;
  }
}


A better solution is to activate manual inventory handling in the General settings, then add eMouseLeftInv and eMouseRightInv blocks to your on_mouse_click handling.

As for the code you tried, mouse.click() is used to simulate a mouse click. It doesn't return anything, and you cannot use it to check whether the button was pressed.
Title: Re: Close Inventory after item selected
Post by: m0rph84 on Thu 27/04/2017 17:55:24
Thank you very much, it worked!

I'll also try the other solution, you meant to set to true this General settings voice?

Override built-in inventory window click handling
Title: Re: Close Inventory after item selected
Post by: Slasher on Thu 27/04/2017 19:28:34
As long as you don't click an inv item then realise you clicked the wrong inv item (laugh)
Title: Re: Close Inventory after item selected
Post by: m0rph84 on Thu 27/04/2017 20:53:15
 :cheesy:

True, but in my case I'm working on a small project and the inventory will have only 4 item max...  :=
Title: Re: Close Inventory after item selected
Post by: Cassiebsg on Thu 27/04/2017 20:56:37
Even with only 4 items... that'll really annoy players if they want to try and combine items.  (laugh)