View Single Post
11/19/14, 05:01 PM   #6
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
In this code:
Lua Code:
  1. item_type = GetItemType(bagId,slotId)
  2. if item_type == "ITEMTYPE_ARMOR" then
  3. --...--

GetItemType(bagId,slotId) could return ITEMTYPE_ARMOR if the item is a piece of armor, but ITEMTYPE_ARMOR is actually an integer, so you can't compare it to a string with:
Lua Code:
  1. if item_type == "ITEMTYPE_ARMOR" then
  2. -- that wont work

You might want to change your tables to something like this:
Lua Code:
  1. local junk_types =
  2. {
  3.     [ITEMTYPE_ADDITIVE]             = true,
  4.     [ITEMTYPE_ALCHEMY_BASE]         = true,
  5.     [ITEMTYPE_AVA_REPAIR]           = true,
  6.     [ITEMTYPE_CLOTHIER_BOOSTER]     = true,
  7.     [ITEMTYPE_CLOTHIER_MATERIAL]    = true,
  8.     [ITEMTYPE_CLOTHIER_RAW_MATERIAL] = true,
  9.     [ITEMTYPE_COLLECTIBLE]          = true,
  10.     [ITEMTYPE_CONTAINER]            = true,
  11.     [ITEMTYPE_DISGUISE]             = true,
  12.     [ITEMTYPE_ENCHANTING_RUNE]      = true,
  13.     [ITEMTYPE_ENCHANTMENT_BOOSTER]  = true,
  14.     [ITEMTYPE_FLAVORING]            = true,
  15.     [ITEMTYPE_FOOD]             = true,
  16.     [ITEMTYPE_GLYPH_ARMOR]      = true,
  17.     [ITEMTYPE_GLYPH_JEWELRY]    = true,
  18.     [ITEMTYPE_GLYPH_WEAPON]     = true,
  19.     [ITEMTYPE_INGREDIENT]       = true,
  20.     [ITEMTYPE_LURE]             = true,
  21.     [ITEMTYPE_NONE]             = true,
  22.     [ITEMTYPE_PLUG]             = true,
  23.     [ITEMTYPE_RAW_MATERIAL]     = true,
  24.     [ITEMTYPE_STYLE_MATERIAL]   = true,
  25.     [ITEMTYPE_TRASH]            = true,
  26. }
Since ItemTypes are all unique integers thier keys in the table will be unique. Set each of their values to true or false, based on whether or not the itemType is supposed to be junk.

Then when your trying to determine if something is junk or not you don't need to call an extra contains(...) function. you can just check that table to see if it is true/false (junk or not junk)
Lua Code:
  1. item_type = GetItemType(bagId,slotId)
  2. if junk_types[item_type] then
  3.    -- item is junk
  4. end

Oh and so the other part of your code would have to be changed to:
Lua Code:
  1. -- notice, no quotes around ITEMTYPE_ARMOR
  2. if item_type == ITEMTYPE_ARMOR then
  3.    local armor_type= GetItemLinkArmorType(item_link)
  4. end

Last edited by circonian : 11/19/14 at 05:09 PM.
  Reply With Quote