WoWInterface - View Single Post - Logging the item my character acquired
View Single Post
05-18-17, 11:16 PM   #1
A Fallenroot Satyr
Join Date: Apr 2017
Posts: 28
Logging the items my character acquired


I am working on a simple addon, which is supposed to log (i.e. save in a text/lua file) the items that I acquire. This is for my own personal use and to keep track of which items I have acquired in the game so far. These items include anything my character can receive via loot, mail, trade, vendor, quest reward, crafting, containers etc.

I have the following code so far:

Lua Code:
  1. LootLog = {}
  3. local f = CreateFrame("Frame")
  4. f:RegisterEvent("BAG_UPDATE")
  6. local function Log_Loot()
  7.     for bag = 0, NUM_BAG_SLOTS do
  8.         for slot = 1, GetContainerNumSlots(bag) do
  9.             local item = GetContainerItemLink(bag, slot)
  10.             local itemName = select(1, GetItemInfo(item))
  12.             table.insert(LootLog, itemName)
  13.         end
  14.     end
  15. end
  17. f:SetScript("OnEvent", Log_Loot)

It gets the item name correctly, it stores the item name correctly in the LootLog.lua file in savedvariables folder, but it stores it 183 times. When I acquire an item, it creates 183 entries with that item's name. When I acquire a second item, it creates another 183 entries with those two items' names. What is wrong with my code? I heard that to do it efficiently, I should register BAG_UPDATE after PLAYER_ENTERING_WORLD. How do I do that?

Thank you very much.

Last edited by Eommus : 05-20-17 at 12:37 AM.
  Reply With Quote