Forum rules - please read before posting.

How to get the list of inventory Category IDs and their names.

edited November 2016 in Technical Q&A
Hi, again, lol. Anyway, I was working on a custom action to, well, use a single crafting menu to simulate many different crafting menus. I have text and appearance switching covered fine, but I want to be able to show the current list of categories so that the user doesn't have to go check the inventory manager every time he wants to use the action. I've found some code I think I could use to limit item categories on the fly, but I haven't found the code to gather the category IDs and the names of the categories... 

by the way the code I was talking about is:

bool AC.MenuInventoryBox.limitToCategory
If True, only inventory items (InvItem) with a specific category will be displayed

List<int> AC.MenuInventoryBox.categoryIDs = new List<int>()
The category IDs to limit the display of inventory items by, if limitToCategory = True

Anyway,  as usual any advice will be greatly appreciated.


  • The code you've posted refers to the MenuInventoryBox - i.e. the InventoryBox's own record of which categories to display, not the actual categories themselves which are stored in the InventoryManager.

    Confusingly, categories in the Inventory Manager are referred to as "bins":


    These are instances of the InvBin class, which stores both an ID and a label.
  • edited November 2016
    Cool, thanks. 

    Well, my idea was to have the inventory box set to limited (if desired), then use the list of IDs (the bins) to create the list of ids to pass to the inventory box (if limited is selected). The thing is I basically need to make an easier way to popup different shops and also crafting menu screens. The game's design requires tons of different crafting areas and shops, all showing only limited categories of items. Making a new menu for each would be a huge chore, and would be a problem if changes are necessary later. (by the way that one is not a VR project)

    Anyway, I must assume I haven't really used crafting only menus yet, only regular inventories, I assume the same bins is to be used with the crafting menu element too? or is it even supported?

    Ps: eh... don't tell the crafting menu element can't limit items by category? =((
  • edited November 2016
    I would definitely recommend getting to grips with the way Crafting works by default before looking into anything more compex on top of it, but no - crafting elements can't be limited by category.  You know AC's development is such that that could be changed, but this is to safeguard against issues such as placing an invalid item on a crafting board.

    I think I need some more explanation as to why you'd need to limit by category, though - a Crafting element can only contain the inventory items the player places inside it, so if you limit what items are in the InventoryBox at the time you're also limiting what can go in the Crafting.  Custom code could access a given Inventory menu behind the scenes and change what categories it displays.
  • edited November 2016
    That's exactly it, I want only related ingredients to be usable only. The game's going to have tons of consumable items and other stuff (like clothing). I only need to limit crafting to 1 item category. I want only the specific related ingredients to be usable. Imagine you get close to a kitchen to cook, and only get "Cooking Ingredients" to craft. But imagine you'll have stuff like Sewing Ingredients, handy craft ingredients, paper craft, etc and the related crafting locations. What we pictured was having a screen with all related items in possession displayed so the player can select from those, more like the inventory works I guess, but the screen should only allow crafting no consumption. You think there's a way I can fake the effect using the inventory box element instead?
  • It's not so much faking the effect, but limiting the InventoryBox to the correct category is what I imagine the solution here: again, the player can only place items from the Inventory into the Crafting element, so if the inventory items available are limited by category, it doesn't matter if technically the crafting UI can accept anything.

    You can change an InventoryBox element's accepted category / categories by modifying it's categoryIDs list, which is a list of the accepted ID numbers:

    MenuInventoryBox myInventoryBox = PlayerMenus.GetElementWithName ("MyMenu", "MyInventory");
    myInventoryBox.categoryIDs.Clear ();
    myInventoryBox.categoryIDs.Add (2);

    That will clear the list and add ID "2" as the only allowed category.  You'd need both the "AC" and "System.Collections.Generic" libraries in your script header for it to work, and would need to run that code before turning on the Menu, so that it recalculates everything out of view.
  • Thanks for the tip, I'll be playing with this later.  ;)
  • edited July 27

    When I use:

    MenuInventoryBox myInventoryBox = PlayerMenus.GetElementWithName ("MyMenu", "MyInventory");

    I get the error:

    CS0266 Cannot implicitly convert type 'AC.MenuElement' to 'AC.MenuInventoryBox'. An explicit conversion exists (are you missing a cast?)

    But I found a working code on another thread:

    MenuElement inventoryBox = PlayerMenus.GetElementWithName("MyMenu", "MyInventory");
    MenuInventoryBox menuInventoryBox = inventoryBox as MenuInventoryBox;

    Then you can use:
    menuInventoryBox.categoryIDs.Clear ();
    menuInventoryBox.categoryIDs.Add (2);

  • Yes, my mistake. You can do the conversion in one line:

    MenuInventoryBox myInventoryBox = PlayerMenus.GetElementWithName ("MyMenu", "MyInventory") as MenuInventoryBox;
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.