Quantcast
WoWInterface - View Single Post - Getting item details on hover
View Single Post
08-02-20, 11:33 PM   #9
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,276
SavedVariables are global, TableOfItems is not really a unique enough name for a global. Same goes for frame names, "myTest" is not really a unique enough name for a global. You might be binding to some other "myTest" button.

Lua Code:
  1. local function addItemToTable(itemID)
  2.     print("add item function fired", itemID)
  3.     for k, v in pairs(TableOfItems) do
  4.         if v == itemID then
  5.             print("Item all ready listed")
  6.         else
  7.             table.insert(TableOfItems, 1, itemID)
  8.             print("Item added to list")
  9.         end
  10.     end
  11. end
This is possibly going to cause problems as you're inserting a new entry for each time there is no match. If you start with an empty table, there will also be no k, v to test against so no new entries will be added... ever.

Lua Code:
  1. local function addItemToTable(itemID)
  2.     if not TableOfItems then -- you could move this here if you don't want to create an event frame
  3.         TableOfItems = {}
  4.     end
  5.     print("add item function fired", itemID)
  6.     local found
  7.     for k, v in pairs(TableOfItems) do
  8.         if v == itemID then
  9.             print("Item all ready listed")
  10.             found = true
  11.             break
  12.         end
  13.     end
  14.     if not found then
  15.         table.insert(TableOfItems, 1, itemID)
  16.         print("Item added to list")
  17.     end
  18. end
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 08-03-20 at 01:05 AM.
  Reply With Quote