Help with identifying empty bag slot

Runes of Magic/Radiant Arcana (http://www.runesofmagic.com)
Post Reply
Message
Author
noobbotter
Posts: 527
Joined: Fri Aug 31, 2012 1:15 pm

Help with identifying empty bag slot

#1 Post 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.
User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Help with identifying empty bag slot

#2 Post 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
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan
noobbotter
Posts: 527
Joined: Fri Aug 31, 2012 1:15 pm

Re: Help with identifying empty bag slot

#3 Post by noobbotter »

Awesome. Thanks Rock.
Post Reply