Jump to content

How to loop through items in inventory?


Eggon

Recommended Posts

I'd like to loop through items in inventory to perform a certain check on each of the items. I have this code (which doesn't work as expected) :

    local player = getPlayer()
    local inventory = player:getInventory()
    local items = inventory:getItems()
    print(items)
    for i, v in ipairs(items) do
        print("i: ", i)
        print("v: ", v)
    end

 

Printing "items" results in a following entry in the console:

Quote

[Clothing{ clothingItemName="some name"}, Clothing{...}, zombie.inventory.types.InventoryContaier@..., zombie.inventory.types.HandWeapon@....]

 

First strange thing about it is that it looks like a mix of 'body containers' and actual items? And the other is that it's enclosed in square brackets, which is not a Lua data type according to my limited knowledge of Lua. ipairing 'items' doesn't throw an error, but it doesn't access the objects either.

 

How can I access items in invntory in form of a iterable table? And what is this strange list in [] that gets logged to the console?

Edited by Eggon
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...