Forum rules - please read before posting.

Inventory - Trying to scroll through collected items, but getting weird gaps [FIXED]

edited October 2018 in Technical Q&A
AC Ver#     1.64.1
Unity Ver#  2018.2.2f1

Hello folks,

I'm experiencing some strange problems when collecting inventory items. I'm trying to give the player the ability to scroll through the list of items they have collected, but depending on the order how items are collected, there seem to be gaps in this list.

In my game, you collect items and then you can scroll through the collected items to shoot them out.

I don't want to bore you with the setup, but here's a bit of context:

1) Player fires a 'use' action to interact with a hotspot
2) Hotspot activates a Action List which using Inventory:Add adds an item to the player inventory
3) The item correctly appears in the visual inventory (accessed via tab)
4) The player can scroll through their inventory using the mouse wheel. Using code like this:

    void MouseScrollwheelSelect()
    {
        if (Input.GetAxis("Mouse ScrollWheel") > 0.0f)
        {
            //Increment inventory slot
            activeInventorySlot++;
        }
        else if (Input.GetAxis("Mouse ScrollWheel") < 0.0f)
        {
            //Decrement inventory slot
            activeInventorySlot--;
        }

        //Clamp the selection to the min and max of the inventory
        activeInventorySlot = Mathf.Clamp(activeInventorySlot, 0, AC.KickStarter.runtimeInventory.localItems.Count);
    }

With me so far? So I'm using runtimeInventory.localItems to get the current state of what the player has on them.

5) Then, things like the UI tell the player what they've selected. Like this:

void ActiveItemChanged()
    {
        (AC.PlayerMenus.GetElementWithName("SelectedItem", "SelectedItemLabel") as AC.MenuLabel).label = KickStarter.runtimeInventory.GetItem(InventorySelection.activeInventorySlot).altLabel;
    }


All of this has worked fine so far, until this afternoon where I tried to add a new item into the game for the player to collect.  If this player collects this new item first, things break.

Here's the list of inventory items in AC, and (hopefully) a clear outline of the problem:



The player starts the game with the first 3 items (actions).

Here's how the player's inventory looks at the start of the game:


And if the player picks up the doughnut item (and only the doughnut item) this is what I'm experiencing:




I want the doughnut to be accessible in slot 3. But it isn't. I want the order of my inventory to be flexible to allow the player to pick up things in any order. I'm not sure why, but inventory items are being devoted to a particular slot in the runtimeInventory.localItems list.

Where am I going wrong?

Comments

  • I fixed it! :D

    The problem was I was using...

    AC.KickStarter.runtimeInventory.GetItem(x) which is the ID of the item.

    When I should have been doing
    AC.KickStarter.runtimeInventory.localItems[x]

    It makes sense to me now. I wasn't actually refering to the list of items the player has but items directly.



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.