Thread Tools Display Modes
02/20/15, 11:53 PM   #1
papaoscar90
Join Date: Feb 2015
Posts: 5
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?
  Reply With Quote
02/20/15, 11:59 PM   #2
papaoscar90
Join Date: Feb 2015
Posts: 5
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?
  Reply With Quote
02/21/15, 12:29 AM   #3
katkat42
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 155
Originally Posted by papaoscar90 View Post
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.
  Reply With Quote
02/21/15, 12:44 AM   #4
papaoscar90
Join Date: Feb 2015
Posts: 5
Thank you very much for the clarification!
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Newcomer - Not sure why only one shows

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