Chapter 11: Page 198 - 'Writing a Bag Scanner'

In the first code block in this section, and thereby in all printed code samples beyond that there is a small subtle error in the BagBuddy_Update() function. Specifically, the returns from GetContainerItemInfo() are not consistent for all types of items, bags being one example. Here are the first few lines of the original function:

 function BagBuddy_Update()
   local items = {}

   local nameFilter = BagBuddy.input:GetText():lower()

   -- Scan through the bag slots, looking for items
   for bag = 0, NUM_BAG_SLOTS do
     for slot = 0, GetContainerNumSlots(bag) do
       local texture, count, locked, quality, readable, lootable, link = GetContainerItemInfo(bag, slot)

       if texture then
         local shown = true

         if BagBuddy.qualityFilter then
           shown = shown and BagBuddy.filters[quality]:GetChecked()
         end

It should be changed to be the following:

 function BagBuddy_Update()
   local items = {}

   local nameFilter = BagBuddy.input:GetText():lower()

   -- Scan through the bag slots, looking for items
   for bag = 0, NUM_BAG_SLOTS do
     for slot = 1, GetContainerNumSlots(bag) do
       -- This code has changed since the book was printed. The return from
       -- GetContainerItemInfo is not consistent for all items, so we will
       -- use the return from GetItemInfo instead.
       local texture, count, locked, qualityBroken, readable, lootable, link = GetContainerItemInfo(bag, slot)

       if texture then
         -- Fetch the name and quality returns so we can use them later
         local name, link, quality = GetItemInfo(link)
         local shown = true


         if BagBuddy.qualityFilter then
           shown = shown and BagBuddy.filters[quality]:GetChecked()
         end

The change is to ignore the quality return from GetContainerItemInfo() and grab the name, link and quality from GetItemInfo(). This should resolve the issues with containers showing up in the listing, and quality being borked up.