Thread Tools Display Modes
05/25/18, 11:01 AM   #1
BoarGules
 
BoarGules's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2017
Posts: 34
Need help with OptionalDependsOn

My addon specifies

## OptionalDependsOn: LibAddonMenu-2.0

and the code does this:

LAM = LibStub('LibAddonMenu-2.0')

With only my addon loaded, this line throws the mystifying exception function expected instead of nil. I say mystifying because if LibStub is not defined then the exception I would expect is attempt to call local/global LibStub (a nil value). I can make the untrapped exception go away by wrapping the assignment in a pcall() but all that does is silence the message.

With LibAddonMenu-2.0 loaded (or any other add-on that uses it) then everything works as expected. So it appears that this bit of the addon has all along been been working only by accident because some other addon had already successfully loaded the library I want.

My question is, what could I be doing wrong? My instincts suggest a typo, but if it is, I just can't see it. There are only 2 lines of code to look at, and 16 filenames to check (LibStub, LibAddonMenu and its 14 controls). Here they are:

lib/LibStub/LibStub.lua
lib/LibAddonMenu-2.0/LibAddonMenu-2.0.lua
lib/LibAddonMenu-2.0/controls/button.lua
lib/LibAddonMenu-2.0/controls/checkbox.lua
lib/LibAddonMenu-2.0/controls/colorpicker.lua
lib/LibAddonMenu-2.0/controls/custom.lua
lib/LibAddonMenu-2.0/controls/description.lua
lib/LibAddonMenu-2.0/controls/divider.lua
lib/LibAddonMenu-2.0/controls/dropdown.lua
lib/LibAddonMenu-2.0/controls/editbox.lua
lib/LibAddonMenu-2.0/controls/header.lua
lib/LibAddonMenu-2.0/controls/iconpicker.lua
lib/LibAddonMenu-2.0/controls/panel.lua
lib/LibAddonMenu-2.0/controls/slider.lua
lib/LibAddonMenu-2.0/controls/submenu.lua
lib/LibAddonMenu-2.0/controls/texture.lua
  Reply With Quote
05/25/18, 11:27 AM   #2
Rhyono
AddOn Author - Click to view addons
Join Date: Sep 2016
Posts: 659
You're calling LAM from your main lua file and you've set your main file to load BEFORE LAM, so you're going to run into an issue.
  Reply With Quote
05/26/18, 02:26 AM   #3
BoarGules
 
BoarGules's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2017
Posts: 34
Thank you. I didn't know that the order of the modules in the .txt file was significant. So it was a typo, of a sort.
  Reply With Quote
05/26/18, 06:49 PM   #4
Dolgubon
 
Dolgubon's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2016
Posts: 408
Originally Posted by BoarGules View Post
Thank you. I didn't know that the order of the modules in the .txt file was significant. So it was a typo, of a sort.
The order of the files in the.txt determines the load order of the files. When a file is loaded it'll run all the code there. If some code is within a function, unless the function is called it won't be run, but the function will be created. The event for add-on initialized is fired anytime an add-ons files are all loaded. Thus, you can put the LibStub file inside that and it won't matter where in the manifest libstuf is.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Need help with OptionalDependsOn

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