Forum rules - please read before posting.

AutoClose the Inventory when the Player navigates away from it

edited November 2018 in Technical Q&A
This is somewhat similar to a recent request by @jamesfootlight (https://www.adventurecreator.org/forum/discussion/8157/inventory-to-close-on-interaction) except that I want the Inventory to automatically close whenever the player moves the mouse away from it

I usually use the classic "MouseOver" mechanism to open and close the Inventory, but it's inappropriate for my current game, because it's a 2d affair with scenes that extend beyond the screen limits, so the player would be forever inadvertently opening the Inventory when they're just trying to click and travel across the scene. So, in this case I've been forced to have them open the Inventory using a keypress. They can of course toggle it off by the same keypress, but I also want the Inventory to autoclose when they've finished using it and they move the mouse away from it

Now, I've already got a working solution:

> I use OnMouseOverMenu to determine when the player has had the mouse over the Inventory
> I've added a Dummy Menu positioned just beneath the Inventory (i.e. lower down on the screen) with an appear type of "During Gameplay"
> When the mouse is over the Dummy Menu, and if they'd already had the mouse over the Inventory, then I close the Inventory

It took a bit of a while to come up with that solution, and it seems to work ok, but it feels a bit... kludgy... so I wonder if there might be a more elegant solution?


Comments

  • edited November 2018
    The "dummy" menu method is a viable solution, though it seems you're also using some custom scripting with your mention of OnMouseOverMenu - whereas you should be able to do it with just one or the other.

    • Method 1
    Rather than having a dummy menu beneath the inventory, you could try a dummy menu that takes up the same area as the Inventory, and set its Appear type to Mouse Over.  Make it invisible, and assign an ActionList when turn off asset that uses the Menu: Change state Action to turn off the Inventory Menu as well.

    Your Inventory menu should have its own Appear type set to Manual, and you can rely on Active inputs to replace the On Input Key method, since this then allows you full control over its display.

    • Method 2
    A simple custom script can handle both the input detection and mouse-over checks.  A Menu's IsPointInside method can be used to determine if the mouse is actually over a given Menu, and it can be turned on/off with TurnOn and TurnOff (again, this requires that the Appear type is set to Manual).

    To get an API reference to a Menu, use:

    Menu myInventoryMenu = PlayerMenus.GetMenuWithName ("Inventory");
  • Thanks Chris

    I should have made it clearer that I was using a scripted solution. I'd not stumbled upon the "IsPointInside" Method, hence the reason for the rather convoluted use of that Dummy Menu

    Now I know about IsPointInside, I'll use that in the way you suggest in Method2


  • and...

    ...it works like a charm
  • For the benefit of others in the future who may have a similar problem, would you consider sharing your code on the wiki or e.g. pasteall.org?
  • No problem

    I'd prefer not to share it on the wiki if that's ok, because that kinda makes it seem semi "official", and I'm by no means the world's greatest programmer (by a long chalk)

    But for anyone else who wants to do something similar (i.e. open the Inventory via a keypress, and then have it automatically close when the player moves the cursor away from it), here's what works for me(*):





    (*) May not work for everyone, the value of your investment may go down as well as up, yada yada


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.