Forum rules - please read before posting.

Is there any workaround for currently held item with the amount?

What I'm trying to do is be able to drag items to a trash button that would delete the item. Now its fine for items that are not stackable but when it comes to stackable items that have maxcount greater than 1 it removes the entire stack.

So lets say on my first inventory slot, I have 8 stack of candies, I take 3 candies and drop it to the trash button which runs this simple code.

    public void RemoveHeldItem()
    {
       InvInstance selectedInstance = KickStarter.runtimeInventory.LastSelectedInstance;

       KickStarter.runtimeInventory.PlayerInvCollection.Delete(selectedInstance);
    }

That code removes the entire 8 stack of candies. I tried other properties too like: "KickStarter.runtimeInventory.HighlightInstance", "KickStarter.runtimeInventory.SelectedInstance" but I cant seem to find one for held item with the held amount. Whats the workaround for this?

Comments

  • SelectedInstance is what you want - this represents the currently-selected item.

    However, the selected item is not a copy of the original item in the menu - the two are the same. If you delete it, you'll delete both.

    The difference in numbers (i.e. 3 selected, 8 in total) comes from the TransferCount vs Count properties. You'll have to account for this difference:

    public void RemoveHeldItem()
    {
        InvInstance selectedInstance = KickStarter.runtimeInventory.SelectedInstance;
        if (InvInstance.IsValid (selectedInstance))
        {
            if (selectedInstance.Count > selectedInstance.TransferCount)
            {
                selectedInstance.Count -= selectedInstance.TransferCount;
            }
            else
            {
                KickStarter.runtimeInventory.PlayerInvCollection.Delete (selectedInstance);
            }
            KickStarter.runtimeInventory.SetNull ();
        }
    }
    
  • ah TransferCount, awesome, I see now thanks.

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.