Thread: I admit defeat
View Single Post
12-06-13, 02:33 PM   #4
MoonWitch
A Firelord
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 455
Originally Posted by Resike View Post
However that table should contain the events you want to register:

Lua Code:
  1. local Events = {
  2.  [1] = "ADDON_LOADED",
  3.  [2] = "COMBAT_LOG_EVENT_UNFILTERED",
  4.  [3] = "ETCETC"
  5. }
  6.  
  7. for k, v in pairs(Events) do
  8.  frame:RegisterEvent(v); -- Register all events for which handlers have been defined
  9. end

Also if you use the in pairs loop then you need to register it's v part not the k.
Thanks

I actually declare my functions like so (Only the Eavu.Print doesn't work, simply because - well the modular aspect got lost somehow. You see how I have to redo the event handler again, even though this is a module?
lua Code:
  1. local __, Eavu = ...
  2. local frame = CreateFrame("Frame")-- sets frame to be used for the hooks, and Eavu to a usable table
  3.  
  4.  
  5. --------------------------------------------
  6. -- Util funcs
  7. --------------------------------------------
  8. function money_to_string(value)
  9.   if value == 0 then return nil end
  10.  
  11.  
  12.   local gold = math.floor(value / 10000)
  13.   local silver = mod(math.floor(value / 100), 100)
  14.   local copper = mod(value, 100)
  15.  
  16.  
  17.   return string.format("|cffffd700%i|r.|cffc7c7cf%02i|r.|cffeda55f%02i|r", gold, silver, copper)
  18. end
  19.  
  20.  
  21. function earned(value)
  22.   return value > 0 and "|cff00ff00Profit|r" or value < 0 and "|cffff0000Loss|r" or nil
  23. end
  24.  
  25.  
  26. function Eavu.MERCHANT_SHOW()
  27. -- Func to AutoRepair from guild if you can repair from guild and haven't exceeded the total amount
  28.   if (CanMerchantRepair()) then -- can we repair from this dude?
  29.     RepairAllItems(CanGuildBankRepair() and GetGuildBankWithdrawMoney() >= GetRepairAllCost())
  30.     Eavu.print('Repaired for:'..GetRepairAllCost())
  31.   end
  32. -- Func to vendor all greys and print out for how much
  33.  
  34.  
  35.   self:UnregisterEvent("MERCHANT_SHOW") -- Unregistering the correct event as well
  36. end
  37.  
  38.  
  39. frame:SetScript("OnEvent", function(self, event, ...)
  40.  Eavu[event](self, ...); -- call one of the functions above
  41. end)
  42.  
  43.  
  44. for k, v in pairs(Eavu) do
  45.  frame:RegisterEvent(k); -- Register all events for which handlers have been defined
  46. end
  Reply With Quote