View Single Post
08/04/23, 02:36 AM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 5,001
Addons all run thorught EVENT_ADD_ON_LOADED in a load order which is defined by the dependencies.
If Dark UI runs the same redirect at it's own EVENT_ADD_ON_LOADED callback it might revert yours which have been done before!


So add DarkUi to your ## OptionalDepends: list in your manifest txt so it will load before your addon and then EVENT_ADD_ON_LOADED of your addon should fire after the one of DarkUi.

For vanilla UI: It should always be called before addons so I don't know why it's not updatig the texture from your addon then properly.
Maybe the compass got a function that calls the texture update after event_add_on_loaded.

Try to use event_player_activated in your case instead of event_add_on_loaded (but only let it do that once! as it will call the same event on every zone change with loading screens too).


Btw: Unregister your EVENT_ADD_ON_LOADED after your addon code was run! Else your callback function will be called for every other addon again and again allthough it does not need to do anything anymore...


And please define functions not global! Add local inf ront else they pollute the global namespace in table _G and will overwrite other addons/vanilla variables and code!
OR define the global functions with a unique name, not SlimCompass or similar.
IF you need themt o be global add 1 global table with your addonName and then add functions to it.
SlimCompass = {}
function SlimCompass.ChangeCompass()
end


In your case a local function SlimCompass() should be enough, same for OnAddOnLoaded!!!


See best practices etc here:
https://www.esoui.com/forums/showthread.php?t=9867



Example code with EVENT_PLAYER_ACTIVATED (fires after EVENT_ADD_ON_LOADED, as player is ready in the ingame wordla dn chat is ready):

Lua Code:
  1. local addOn = {
  2.     name =      "SlimCompass",
  3.     version =   "1"
  4. }
  5. local addonName = addOn.name
  6. local compassTextureOrig = "esoui/art/compass/compass.dds"
  7. local compassTextureMine = "slimcompass/textures/sc_compass.dds"
  8.  
  9. local function SlimCompass()
  10.     RedirectTexture(compassTextureOrig, compassTextureMine)
  11. end
  12.  
  13. local function OnPlayerActivated(eventCode, wasFirst)
  14.     --Only call this event callback once
  15.     EVENT_MANAGER:UnregisterForEvent(addonName, eventCode) --will unregister EVENT_PLAYER_ACTIVATED again so it's only executed once
  16.  
  17.     SlimCompass() --Change compass again
  18. end
  19.  
  20. local function OnAddOnLoaded(eventCode, addOnName)
  21.     if addOnName ~= addonName then return end
  22.     EVENT_MANAGER:RegisterForEvent(addonName, EVENT_PLAYER_ACTIVATED, OnPlayerActivated)
  23.     SlimCompass() --Change compass now, maybe you can remove this here if EVENT_PLAYER_ACTIVATED works alone
  24.  
  25.     EVENT_MANAGER:UnregisterForEvent(addonName, EVENT_ADD_ON_LOADED)
  26. end
  27.  
  28. EVENT_MANAGER:RegisterForEvent(addonName, EVENT_ADD_ON_LOADED, OnAddOnLoaded)

Last edited by Baertram : 08/04/23 at 02:44 AM.
  Reply With Quote