Hello,
I'm trying to close the inventory after an inventory item has been selected.
This is my left click function:
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()
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.
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.
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
As long as you don't click an inv item then realise you clicked the wrong inv item (laugh)
:cheesy:
True, but in my case I'm working on a small project and the inventory will have only 4 item max... :=
Even with only 4 items... that'll really annoy players if they want to try and combine items. (laugh)