Thread Tools Display Modes
03/13/24, 06:20 AM   #1
static_recharge
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 35
Splitting up Add-on into Multiple Files

Hello I was hoping someone could explain to me good practices (and how they work) for splitting up a large add-on into multiple files. For example having one file for the settings menu information (settingsmenu.lua for example). I'm trying to mimic what I see in other add-ons by using _G[] and whatnot but I'm just not understanding the full picture and how methods play a role into this. I've tried the following code:

Start of StaticsRecruiter.lua
Code:
local SR = _G['StaticsRecruiter']
SR.addonName = "Static's Recruiter"
Start of SettingsMenu.lua
Code:
local SR = _G['StaticsRecruiter']
function SR:Create settings menu()
...
end
When my code runs it says it's attempting to index a nil value at the
function SR:Create settings menu()
line.

Any help or pointing in the right direction is appreciated. I tried searching the forums but I couldn't find anything on the subject. I might have been using the wrong terms. Thanks in advance.
  Reply With Quote
03/13/24, 08:10 AM   #2
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
Check the wiki. There are some tutorials. This one for example is exactly about what you are asking.
  Reply With Quote
03/13/24, 11:21 AM   #3
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,989
Also remember that the : notation for function calls shoud be used for created objects of classes (created via ZO_Object:SubClass() e.g. where you can use self to reference the created object), and not simple tables {}.

So if SR = {} only, better do not use function SR:FunctionName but SR.FunctionName and calls as well via . and not : notation.
Easier to read and to understand.

In the end it works with : too, right. But the usage of "self" for simple tables is not intended afaik
  Reply With Quote
03/13/24, 01:23 PM   #4
static_recharge
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 35
Thank you for the quick replies everyone. It has been a while since I looked at that tutorial and had forgotten that it showed what I needed. I'll read that over again. Cheers!
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Splitting up Add-on into Multiple Files


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