Page 1 of 1

how to know if item has inventory (ItemWithInventory ) ?

Posted: Thu Jul 07, 2016 12:51 pm
by Kruparker
Everywhere on API doc for LuaItemStack,
members refer to "Can only be used if this is ItemWithInventory"

but there's no
ItemWithInventory :: Booleen [Read-only]
return true / false

get_inventory
Should
Return value
or nil if there is no inventory with the given index.
but Crash because " This is not an item-with-inventory."

Prototype / groups have nothing more.

So, please : How do I know if an item has an inventory or not (blueprint-book for example, or any new item defined in a mod ) ?

Re: how to know if item has inventory (ItemWithInventory ) ?

Posted: Thu Jul 07, 2016 2:10 pm
by Helfima
u can catch the exception with pcall

Code: Select all

local ok , err = pcall(function()
		--the code to get_inventory
	end)
	if not ok then
		--code when error
	else
		--code when ok
	end

Re: how to know if item has inventory (ItemWithInventory ) ?

Posted: Thu Jul 07, 2016 2:52 pm
by Kruparker
indeed, that's a way to do it, thank's

I'm not used to throw an exception to make an "if", but why not. =)