Page 1 of 1

Help with identifying empty bag slot

Posted: Mon Dec 16, 2013 12:09 pm
by noobbotter
I have a part of code where I log my current inventory:

Code: Select all

logInfo(player.Name, "\tSlot \t\tQuality\t\tValue\t\tItem Name",false)
for slot = 61, 120 do
			local item = inventory.BagSlot[slot]
			if item then
				logInfo(player.Name, "\t"..slot.."\t\t"..item.Quality.."\t\t"..item.Value.."\t\t"..item.Name,false)
			end
		end
the problem that I'm seeing with this is that it always creates an entry for every bag slot, regardless of if it has something in it or not. Sample output:

Code: Select all

	Slot 		Quality		Value		Item Name
	61		0		0		<EMPTY>
	62		2		1071		Harvest God Star Stone
	63		3		10		Recipe - Sealer's Totem Flag
	64		8		0		Arcane Transmutor Charge
	65		0		0		<EMPTY>
	66		2		10		Recipe - Large Exquisite Advanced Iron Chest
	67		0		15		Phirius Potion - Type B
	68		0		0		<EMPTY>
	69		3		2		Lyliya's Colorful Glass Bead
	70		0		0		<EMPTY>
	71		0		15		Phirius Elixir - Type B
	72		2		10		Recipe - Large Exquisite Superior Iron Chest
	73		0		0		<EMPTY>
	74		0		0		<EMPTY>
	75		0		0		<EMPTY>
	76		0		0		<EMPTY>
	77		0		0		<EMPTY>
	78		0		0		<EMPTY>
	79		0		0		<EMPTY>
	80		0		0		<EMPTY>
How would I get that to not log when the slot is empty? I thought the "if item then" would only log when there's an item in the slot, but apparently not.

Re: Help with identifying empty bag slot

Posted: Mon Dec 16, 2013 12:31 pm
by rock5
An empty slot still returns a table of information about that slot, such as its bagid, that it's empty, whether its locked, etc. After all, that slot exists whether it's empty or not. As you can see empty slots have a name of "<EMPTY>" and an id of 0. So you could check for name or id but know that the name causes problems in xml files because of those brackets. So typically we use the id.

Code: Select all

if item.Id ~= 0 then
The same is true when we count empty slots

Code: Select all

inventory:itemTotalCount(0)
Actually you could also use the 'Empty' value instead of the Id. It's basically the same thing but reads better.

Code: Select all

if not item.Empty then

Re: Help with identifying empty bag slot

Posted: Mon Dec 16, 2013 12:46 pm
by noobbotter
Awesome. Thanks Rock.