Forum rules - please read before posting.

Inventory to list

I am trying to gather the contents of a category of items and store them inside a list. each item within the lost needs to be given its own instance of a frame object containing the inventories main graphic.

I have tried using a for each statement to assign each article with its own object, but the inventories store entries as ints. Will storing these ints in an array or list store the inventory objects? Or am I completely wrong in how I am going about this?

Comments

  • What do you mean by "article", and where are you getting ints from?

    If the ints refer to an item's ID, then you can use that ID to get the original Inventory item in the Inventory Manager, i.e.:

    int myItemID = 0;
    InvItem myItem = KickStarter.inventoryManager.GetItem (myItemID);

  • By article, I mean the item within the inventory.

    Each item in the inventory under a certain category is to be stored and assigned an object in a UI menu with its main graphic as a logo.

  • The code for what we are trying to do is here in this pasteall: http://pasteall.org/1509251/csharp

  • GetItemsInCategory returns an array of InvItem classes - not an integer. See its entry in the Scripting guide.

    foreach (InvItem item in KickStarter.inventoryManager.GetItemsInCategory(0))
    {
        Texture mainGraphic = item.tex;
    }
    
  • I tried that way, but the foreach will throw me an error saying it can only handle integers.

    InvItem Evidencelist = KickStarter.inventoryManager.GetItemsInCategory(0)*;
    
    
            foreach* (InvItem item in KickStarter.inventoryManager.GetItemsInCategory(0))
            {
                Instantiate(Photo, EvidenceGridComp.transform); // Add new objects to the new 
                Texture mainGraphic = item.tex;
            }
    
    *Error
    

    I tried converting it to a for statement instead by using the recommended fix VS offered.

    IList list = KickStarter.inventoryManager.GetItemsInCategory(0);
            for (int i = 0; i < list.Count; i++)
            {
                InvItem item = (InvItem)list[i];
                Instantiate(Photo, EvidenceGridComp.transform); // Add new objects to the new 
    
                Texture mainGraphic = item.tex;
            }
    

    It fixed the error but the photo objects are still not spawning.

    We also keep getting this error message every frame. We are sure it is being caused by the code in Update().

    NotImplementedException: The method or operation is not implemented.
    AC.InventoryManager.GetItemsInCategory (System.Object categoryID) (at Assets/AdventureCreator/Scripts/Managers/InventoryManager.cs:59)
    CaseManager.Update () (at Assets/Scripts/CaseManager.cs:144)

  • Just in case. I am using canvases to hold the horizontal layout grid I am using to sort the inventory objects.

  • edited February 2019

    What are your AC and Unity version numbers?

    GetItemsInCategory is on line 2106 in the current release, and returns an array of InvItems. Have you modified AC's code in any way? I can't see how you'd be getting such errors with the current AC release.

  • I have the last release, I will back up and update to the most current release.

    I have not modified AC's code.

  • edited February 2019

    Please be specific - "last" being which one, and again - your Unity version.

    Let's see the full script itself - as well as more detail about what it is exactly you're trying to do.

  • edited February 2019

    Hi Chris.

    What I am trying to do is get items from the inventory category "evidence" and instantiate them into a grid with a frame object "photo".

    I reconfigured the script to find a way around the errors. By feeding the blank object into the script initially via the inspector, the system started to work.

    The new code is here: http://pasteall.org/1515844/csharp

    The only problem with the system is that the evidence icons are not iterating correctly, they are leaving the first one blank before correctly assigning the next.

  • You're updating the Image component of the prefab, not the instantiated object:

    Image photoImageBlank = EvidencePhoto.transform.GetChild(0).GetComponent<Image>();
    
  • Ah. Thank you!

  • Hi Chris. One last thing with the evidence pictures. Is it possible to get the image value from an instantiated object? So, for example. If I wanted to get the InvItem image value of an instantiated object.

  • The InvItem and the instantiated object are two different things - I don't know what you're assigning to as your instantiated object, but an InvItem isn't an asset or prefab file that you can assign.

    To get a reference to an item's graphic, right-click on the field's label in the Inventory Manager.

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.