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:
local f = CreateFrame("Frame")
for bag =0, NUM_BAG_SLOTS do
for slot =1, GetContainerNumSlots(bag)do
local item = GetContainerItemLink(bag, slot)
local itemName = select(1, GetItemInfo(item))
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?