ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Newcomer - Not sure why only one shows (https://www.esoui.com/forums/showthread.php?t=4321)

papaoscar90 02/20/15 11:53 PM

Newcomer - Not sure why only one shows
 
I have been doing the "Writing your first addon" tutorial. I get to the part where it should show whether the player enters and exits combat but nothing shows up. So I backed up a little bit and started to try and figure out what is going on. I put in a couple d() with small messages and found out my .AddOnLoaded function never starts.... I followed the tutorial and just cant seem to figure out what is going on.

Folder Struct:
FooAddon
->FooAddon.txt
->FooAddon.lua

Lua Code:
  1. FooAddon = {}
  2.  
  3. FooAddon.name = "FooAddon"
  4.  
  5. function FooAddon:Initialize()
  6.     d("Initialized")
  7. end
  8.  
  9. function FooAddon.OnAddOnLoaded(event, addonName)
  10.     if addonName == "FooAddon" then
  11.         FooAddon:Initialize()
  12.     end
  13. end
  14.  
  15. function FooAddon.Activated()
  16.     d("Activated")
  17. end
  18.  
  19. EVENT_MANAGER:RegisterForEvent("FooAddon", EVENT_ADD_ON_LOADED, FooAddon.OnAddOnLoaded)
  20. EVENT_MANAGER:RegisterForEvent(FooAddon.name, EVENT_PLAYER_ACTIVATED, FooAddon.Activated)

Now I tried the ADD_ON_LOADED one with both "FooAddon" and FooAddon.name. Neither executes the d(). Can somebody tell me what is goin on?

papaoscar90 02/20/15 11:59 PM

I may have just answered my own question, but am still looking to make sure I am along the right lines.

This:
Lua Code:
  1. FooAddon = {}
  2.  
  3. FooAddon.name = "FooAddon"
  4.  
  5. function FooAddon.Activated()
  6.     d("Activated")
  7. end
  8.  
  9. function FooAddon:Initialize()
  10.     d("Initialize")
  11.     EVENT_MANAGER:RegisterForEvent(FooAddon.name, EVENT_PLAYER_ACTIVATED, FooAddon.Activated)
  12. end
  13.  
  14. function FooAddon.OnAddOnLoaded(event, addonName)
  15.     if addonName ~= "FooAddon" then
  16.     return
  17.     else
  18.         FooAddon:Initialize()
  19.     end
  20. end
  21.  
  22.  
  23. EVENT_MANAGER:RegisterForEvent("FooAddon", EVENT_ADD_ON_LOADED, FooAddon.OnAddOnLoaded)

This outputs the "Activated" again but not Initialize. So it is indeed checking the names of the addons and executing the Initialize() function. Am I correct in assuming that the OnAddOnLoaded function just completes itself before the game is actually out of the loading screen? So anything that it tries to do just doesn't work because the game hasn't actually finished loading?

katkat42 02/21/15 12:29 AM

Quote:

Originally Posted by papaoscar90 (Post 18943)
I may have just answered my own question, but am still looking to make sure I am along the right lines.

This:<snip>

This outputs the "Activated" again but not Initialize. So it is indeed checking the names of the addons and executing the Initialize() function. Am I correct in assuming that the OnAddOnLoaded function just completes itself before the game is actually out of the loading screen? So anything that it tries to do just doesn't work because the game hasn't actually finished loading?

That is correct. More specifically, Addons are loaded before the chat system, and it's the chat system that displays the output of d(). I think Bug Eater can capture and display stuff that was "d()'d" before chat is set up, if you're curious.

papaoscar90 02/21/15 12:44 AM

Thank you very much for the clarification!


All times are GMT -6. The time now is 02:50 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI