Quantcast
WoWInterface - View Single Post - [AceAddon-3.0] Module doesn't fire OnEnable/OnDisable function
View Single Post
12-27-17, 04:08 AM   #1
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
[AceAddon-3.0] Module doesn't fire OnEnable/OnDisable function

Hi again all,

I personally thought that I'm pretty familiar with AceAddon-3.0, but seems I'm not

Okay, so I'm currently trying to make an AceAddon-3.0 based addon with three different modules that gets enabled & disabled based on player's current specialization and here's what I have done so far.

init.lua
Lua Code:
  1. local name, ns = ...;
  2.  
  3. -- Upvalue
  4. local _G = _G;
  5.  
  6. -- Addon
  7. local E = LibStub("AceAddon-3.0"):NewAddon(name, "AceEvent-3.0");
  8. local L = LibStub("AceLocale-3.0"):GetLocale(name, false);
  9. local D = {};
  10.  
  11. ns[1] = E; -- Engine
  12. ns[2] = L; -- Locale
  13. ns[3] = D; -- Defaults
  14.  
  15. _G[name] = ns;
  16.  
  17. -- Variable
  18. local specNameByID = { -- Needed for non English client
  19.     [259] = "Assassination",
  20.     [260] = "Outlaw",
  21.     [261] = "Subtlety",
  22. }
  23.  
  24. -- Function
  25. function E:OnInitialize()
  26.     self.db = LibStub("AceDB-3.0"):New(name .. "DB", D, true);
  27.  
  28.     self:ACTIVE_TALENT_GROUP_CHANGED(nil, nil, nil, true);
  29. end
  30.  
  31. function E:OnEnable()
  32.     print(E:GetName() .. " OnEnable");
  33. end
  34.  
  35. function E:OnDisable()
  36.     print(E:GetName() .. " OnDisable");
  37. end
  38.  
  39. function E:ACTIVE_TALENT_GROUP_CHANGED(event, arg1, arg2, isOnInitialize)
  40.     local db = self.db.global;
  41.  
  42.     local newSpecID = GetSpecializationInfo(GetSpecialization());
  43.  
  44.     if isOnInitialize or (db.currentSpecID and db.currentSpecID ~= newSpecID) then
  45.         db.currentSpecID = newSpecID;
  46.  
  47.         for id, name in pairs(specNameByID) do
  48.             local module = self:GetModule(name);
  49.  
  50.             (id == db.currentSpecID and module.Enable or module.Disable)(module);
  51.         end
  52.     end
  53. end
  54.  
  55. E:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED");

Outlaw.lua
Lua Code:
  1. local E, L, D = unpack(select(2, ...));
  2.  
  3. -- Module
  4. local M = E:NewModule("Outlaw");
  5.  
  6. -- Variable
  7. local RtBIDs = {
  8.     199603, -- Jolly Roger
  9.     193358, -- Grand Melee
  10.     193357, -- Shark Infested Waters
  11.     193359, -- True Bearing
  12.     199600, -- Buried Treasure
  13.     193356, -- Broadsides
  14. }
  15.  
  16. local CotDID = 202665; -- Curse of the Dradeblades
  17.  
  18. local SaDID = 5171; -- Slice and Dice
  19.  
  20. local selectedSaD;
  21.  
  22. local InitializeObjects, ManageObjectStates;
  23.  
  24. -- Function
  25. function M:OnInitialize()
  26.     InitializeObjects();
  27. end
  28.  
  29. function M:OnEnable()
  30.     print(M:GetName(), "OnEnable");
  31.  
  32.     local holder = self.holder;
  33.     holder:Show();
  34.     holder:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED");
  35.     holder:RegisterUnitEvent("UNIT_AURA", "player");
  36.     holder:SetScript("OnEvent", function(self, event, ...)
  37.         M[event](M, ...);
  38.     end);
  39.  
  40.     ManageObjectStates();
  41. end
  42.  
  43. function M:OnDisable()
  44.     print(M:GetName(), "OnDisable");
  45.  
  46.     local holder = self.holder;
  47.     holder:UnregisterAllEvents();
  48.     holder:Hide();
  49. end

The current problem is that after calling Enable/Disable functions within ACTIVE_TALENT_GROUP_CHANGED method on addon initialization, the module's OnEnable/OnDisable functions don't get called on login, reload and etc, but only gets affected when the player actually changes his/her spec.
(talent changes are not considered on purpose)

According to the description in AceAddon-3.0.lua file, OnEnable functions get called during the PLAYER_LOGIN event (normally I'd say right after OnInitialize function gets called) and the state of modules are changed while initialization (L#50 of init.lua), thus I can't really think why it is not working

Am I doing something wrong?

Last edited by Layback_ : 12-27-17 at 05:14 AM.
  Reply With Quote