Quantcast
Logging the item my character acquired - WoWInterface
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
05-18-17, 11:16 PM   #1
Eommus
A Fallenroot Satyr
Join Date: Apr 2017
Posts: 28
Logging the items my character acquired

Hi,

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 = {}
  2.  
  3. local f = CreateFrame("Frame")
  4. f:RegisterEvent("BAG_UPDATE")
  5.  
  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))
  11.            
  12.             table.insert(LootLog, itemName)
  13.         end
  14.     end
  15. end
  16.  
  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
 

WoWInterface » Developer Discussions » Lua/XML Help » Logging the item my character acquired

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off