Forum rules - please read before posting.

How do you place items in specific inventory slots using scripting (controller/keyboard only) ?

After losing a load of progress on my game (don't rely on physical media only, kids - hard drives can go wandering!) I managed to rebuild my resident evil style inventory system from scratch.
I use entirely custom scripting - events to check whether the inventory boxes have been selected, then a submenu that lets you use stuff (the items' interactions), discard things you don't want, and finally, to combine and reorder items.
This is where I've run into issues.
I can't, for the life of me, figure out what I should be doing to plonk a selected item into the slot the "cursor" is hovering over.
I assume it's something to do with reordering their place on a list, but I'm a bit of a brainlet, so I couldn't quite figure out what to do!
The relevant stuff I've got is thus:

        hoverItem = KickStarter.runtimeInventory.HoverInstance;
        if (hoverItem != null)
        {
            if (hoverItem != selectedItem)
            {   
             Debug.Log("Combine this crap");
             selectedItem.Combine(hoverItem);
            }
            else
            {
             Debug.Log("put the item back where I found it");  
            //just deselect it instead.
            }
        }
        else
        {
            Debug.Log("put the item down in this empty spot");
            //But how? How do I actually put it into the slot?? 
        }

        ClearSelected();

Any help would be rad - just a pointer in the right direction. :) Cheers!

Comments

  • If you're still relying on an InventoryBox element, such code should typically be placed inside an OnMenuElementClick event hook - is this the case here?

    An InventoryBox element doesn't store items itself - it just displays items within an InvCollection class. Placing an item in a given slot is therefore a case of modifying the InvCollection itself (and then calling PlayerMenus.ResetInventoryBoxes() to update the Menus).

    The OnMenuElementClick event includes a "slot" parameter to represent which slot index was clicked - you can use this to determing where to insert the item. Though, if your InventoryBox supports scrolling, you'll need to account for the offset with:

    slot += element.GetOffset ();
    

    To insert an item into the Player's InvCollection, you can then call:

    KickStarter.runtimeInventory.PlayerInvCollection.Insert (myInvItem, slot);
    
  • Ah! I wondered what the slot parameter was for. Awesome! Thank you. I'm using an InventoryBox, and definitely doing it within the OnMenuElementClick event too. So this will sort it out perfectly!:)

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.