Thread Tools Display Modes
05-31-14, 04:45 PM   #1
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Issue with Ace3 not loading AddOn

Hi, I have never had this issue before but recently started and need help. When I load WoW and login for the first time on a character it does not load the AddOn I am making until I "/reload" the UI.

I will link all the relevant code but if more is required I will try to upload the entire thing somewhere:

Lua Code:
  1. MayronUI = LibStub("AceAddon-3.0"):NewAddon("MayronUI")
  2.  
  3. function MayronUI:OnInitialize()
  4.     self.db = LibStub("AceDB-3.0"):New("MayronUIdb", defaults)
  5. end

And then I have an OnEnable function where nothing in this body will load:

Lua Code:
  1. function MayronUI:OnEnable()
  2. ...
  3. end

I am no expert with Ace3 but shouldn't this work? So confused, thanks for reading. I will try to upload the rest

Last edited by Mayron : 05-31-14 at 04:47 PM.
  Reply With Quote
05-31-14, 06:15 PM   #2
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Yeah that'll work. Sounds like you'd be getting some error related to missing API data on first login.

How can you tell it's not working?
__________________
Grab your sword and fight the Horde!
  Reply With Quote
06-01-14, 02:07 AM   #3
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Originally Posted by Lombra View Post
Yeah that'll work. Sounds like you'd be getting some error related to missing API data on first login.

How can you tell it's not working?
Ah so at least I can cross that off the list. No idea why no Lua error is appearing then. The OnEnable function shows a few visual frames on the screen and does not do it when I launch WoW and login for the first time and requires me to have to reload the UI with the slash command which is a pain.

I am trying to bind the Shadowed Unit Frames onto the frames I create so in the ToC I have:

## OptionalDeps: ShadowedUnitFrames

The Entire OnEnable function is this:
Lua Code:
  1. local MayronUI = LibStub("AceAddon-3.0"):GetAddon("MayronUI") -- Just added this but does not change anything.
  2.  
  3. function MayronUI:OnEnable()
  4.     -- Constants:
  5.     local MUI = MayronUI.db.profile;
  6.  
  7.     local muiBottom = CreateFrame("Frame", "MUI_Bottom", UIParent, "MUI_Bottom") -- using XML template which is loaded first.
  8.     local currentProfile = nil
  9.     local function RegisterEvents(self, ...)
  10.         for i=1,select('#', ...) do
  11.             self:RegisterEvent(select(i, ...));
  12.         end
  13.     end
  14.     muiBottom.RegisterEvents = RegisterEvents;
  15.     muiBottom:RegisterEvents("PLAYER_ENTERING_WORLD", 'PLAYER_TARGET_CHANGED', "PLAYER_LOGOUT");
  16.     muiBottom:SetScript("OnEvent", function(self, event, ...)      
  17.         if ( event == "PLAYER_TARGET_CHANGED" ) then
  18.             if ( UnitExists("target") ) then
  19.                 MUI_BottomRightName:Show();
  20.                 MUI_BottomUnitFrames:SetTexture(MUI_MEDIA.."Double.tga");
  21.             else
  22.                 MUI_BottomRightName:Hide();
  23.                 MUI_BottomUnitFrames:SetTexture(MUI_MEDIA.."Single.tga");
  24.             end
  25.         elseif ( event == "PLAYER_ENTERING_WORLD" ) then -- Aligning Supported AddOns with MUI_Bottom
  26.             if ( IsAddOnLoaded("ShadowedUnitFrames") and ShadowUF.db ) then
  27.                 currentProfile = ShadowUF.db:GetCurrentProfile();
  28.                 SUFUnittargettarget:ClearAllPoints();
  29.                 SUFUnittargettarget:SetPoint("BOTTOM", "MUI_Bottom", "CENTER", 0, 3);
  30.                 local SUF = _G.ShadowedUFDB["profiles"][currentProfile]["positions"]["targettarget"];
  31.                 _G.SUF["point"] = "BOTTOM"; _G.SUF["anchorTo"] = "MUI_Bottom";
  32.                 _G.SUF["relativePoint"] = "CENTER"; _G.SUF["x"] = 0; _G.SUF["y"] = 3;          
  33.                 ShadowUF.Layout:Reload();
  34.                
  35.                 CastingBarFrame:UnregisterAllEvents();
  36.                 CastingBarFrame:Hide();
  37.                 MUI_PlayerCastBar:ClearAllPoints();
  38.                 MUI_PlayerCastBar:SetPoint("TOPLEFT", SUFUnitplayer, "TOPLEFT", 1, -0.5);
  39.                 MUI_PlayerCastBar:SetSize((SUFUnitplayer:GetWidth()-2), 26.5);
  40.                
  41.                 MUI_TargetCastBar:ClearAllPoints();
  42.                 MUI_TargetCastBar:SetPoint("TOPLEFT", SUFUnittarget, "TOPLEFT", 1, -0.5);
  43.                 MUI_TargetCastBar:SetSize((SUFUnittarget:GetWidth()-2), 26.5);
  44.                
  45.                 self:UnregisterEvent("PLAYER_ENTERING_WORLD");
  46.             end
  47.         elseif ( event == "PLAYER_LOGOUT" ) then
  48.             _G.ShadowedUFDB["profiles"][currentProfile]["positions"]["targettarget"]["anchorTo"] = "UIParent";
  49.         end
  50.     end)
  51. end


Using "GetAddon" at the start of the file does not seem to help and is something I just tried recently to fix it with no luck.

EDIT: Also I wanted to use "PLAYER_LOGIN" rather than "PLAYER_ENTERING_WORLD" but this never gets triggered in the OnEnable function. Don't think it matters though.

Last edited by Mayron : 06-01-14 at 02:14 AM.
  Reply With Quote
06-01-14, 02:31 AM   #4
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
So I just found out the body of the function is not the problem because this does not work either:

Lua Code:
  1. function MayronUI:OnEnable()
  2.     print("TEST")
  3. end

To load this file with this function in I am using embeds.xml in my TOC file to load and in the embeds I am using (without the <Ui> tags):

Lua Code:
  1. <!-- MUI Files: -->
  2.     <Script file="Core.lua"/>
  3.     <Include file="Modules\BottomUI.xml"/>
  4.     <Include file="Modules\CastBars.xml"/>
  5.     <Include file="Modules\ToolTips.xml"/>

The BottomUI.xml file has this at the start:
Lua Code:
  1. <Script file="BottomUI.lua"/>

which has the function I listed above. I don't think any of this is the problem either. I think that's everything I can link to without uploading the files.
  Reply With Quote
06-01-14, 05:55 AM   #5
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
I'm not sure, but a few things:

In Ace3 I think, OnEnable *is* PLAYER_LOGIN, so you can just put your PLAYER_ENTERING_WORLD code there.

Print something at the bottom of the file in the main scope to make sure it's actually being fully loaded. Also get an addon for errors if you haven't already, or you won't see errors that occur during the loading process.

If none of this helps you should post all your files.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
06-01-14, 10:12 AM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Mayron View Post
To load this file with this function in I am using embeds.xml in my TOC file to load and in the embeds I am using (without the <Ui> tags):
This is a bad idea for several reasons:

1. It's unnecessary complicated. Just list the files you want to load right in your TOC file. There's no need to list one file instead that does nothing but list other files. If you're embedding 42 libraries and want to move those file references into an embeds.xml file, or your addon has 300 modules and you want to move those references into a modules.xml file, that's one thing (though I'd argue that you should probably give some very serious thought to streamlining your addon at that point) but there's no reason to have an XML file just to load your addon's core files.

2. It's unnecessarily slowing down your addon's load time by adding another file to read from disk (which is generally the slowest part of loading an addon) and parse, without conferring any benefit of any kind.

3. Some third-party addon updating programs may still be hard-coded to assume that a file named "embeds.xml" is listing embedded libraries, since that was an unofficial standard at one point, and strip it or its contents for users who indicate a preference for standalone libraries, which will break your addon.

Other than that, without seeing your whole addon, there's really no way for anyone to even begin to guess what's going on here. The snippets you posted are confusing at best -- is the OnEnable function in a different file than the OnInitialize function? if not, why is there a GetAddon line in the same file as the NewAddon line? etc.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
06-01-14, 10:28 AM   #7
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Originally Posted by Phanx View Post
Other than that, without seeing your whole addon, there's really no way for anyone to even begin to guess what's going on here. The snippets you posted are confusing at best -- is the OnEnable function in a different file than the OnInitialize function? if not, why is there a GetAddon line in the same file as the NewAddon line? etc.
That is completely understandable, just need to setup GitHub again and post it there. I thought it was going to be a typical beginners error with the use of Ace3 so thought I would post the major parts first just in case uploading the entire code was going to be unnecessary.

Yes, OnEnable function is in a different file. I should have said that first. The OnInitialize function is called before it in the Core.lua file.

I will modify the structure of the files to make it less confusing and redundant. Then will post it.
Thanks for the feedback.

I usually like to split many major parts of my AddOn into multiple files as it helped me organise my projects easier but if that causes extra load times that I was unaware of then I should really stop using that approach.

Last edited by Mayron : 06-01-14 at 10:34 AM.
  Reply With Quote
06-01-14, 10:51 AM   #8
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Mayron View Post
... just need to setup GitHub again and post it there.
You can attach ZIP files to forum posts.

Originally Posted by Mayron View Post
I usually like to split many major parts of my AddOn into multiple files as it helped me organise my projects easier but if that causes extra load times that I was unaware of then I should really stop using that approach.
Well, having 100 files that each have 1000 lines of code will make your addon load much more slowly, but having 100,000 lines of code in a single file will make your addon much harder to maintain. If you're using a fancy IDE that lets you create "virtual files" or something, then by all means shove everything into one actual file to reduce disk read times, but otherwise just be sensible -- divide your code into logical categories like "core loading functions" and "shared utility functions" and "action bar functions" and have one file per category. I can't really think of any reason for putting a single addon's OnInitialize and OnEnable functions in different files; a "one function per file" approach isn't really a good one in the WoW addon environment ... or in any other environment I'm familiar with, though I'm willing to accept that one might exist.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
06-01-14, 04:17 PM   #9
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Thanks Phanx, Usually I only keep major elements of an AddOn in separate files. In this case I have my "BottomUI" module in one, my CastBar mod in another, and Chat Module in another. Other smaller things I will merge into one file but I will think about placing the other ones I have mentioned into the same folder. The chat mod may use a lot of lines though.

The problem seems to have been fixed however if I place the code out side of "PLAYER_ENTERING_WORLD" that involves using Shadowed Unit Frame elements then I get:

attempt to index field "db" (a nil value)

For line: currentProfile = ShadowUF.db:GetCurrentProfile();

Suggesting that Shadowed Unit Frames was not loaded even though I have it set as an Optional Dependency in the toc file and:

Originally Posted by Lombra View Post
In Ace3 I think, OnEnable *is* PLAYER_LOGIN, so you can just put your PLAYER_ENTERING_WORLD code there.
So confused about what to do with this code involving SUF.
  Reply With Quote
06-01-14, 04:36 PM   #10
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Hm, SUF seems to create its database on PLAYER_LOGIN, and your PLAYER_LOGIN (OnEnable) must be firing before that. You might need to use PLAYER_ENTERING_WORLD, after all.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
06-01-14, 04:43 PM   #11
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Originally Posted by Lombra View Post
Hm, SUF seems to create its database on PLAYER_LOGIN, and your PLAYER_LOGIN (OnEnable) must be firing before that. You might need to use PLAYER_ENTERING_WORLD, after all.
Ah well at least its working and was not any unknown bug causing it. Well now everything is awesome so thanks guys
  Reply With Quote
06-01-14, 06:31 PM   #12
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
The order in which frames receive events isn't guaranteed. In practice it seems to usually be the case that they receive the events in the order they registered for them (eg. if Frame A registers for Event X, and then Frame B registers for the same event, Frame A receives the event first, then once it's done running its OnEvent script, Frame B receives the event) but the order not specifically defined, and you shouldn't rely on it working that way. If you need to make sure your function always runs after another addon's function, use a hook instead.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Issue with Ace3 not loading AddOn


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