Thread Tools Display Modes
07-31-11, 10:12 PM   #1
barbol12
A Cyclonian
 
barbol12's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2010
Posts: 42
functions from other addons

hello, apparently i cant get this to work..

i have an addon that has a few functions on them(this addon loads before main addon). But when i try to use them in my main addon it doesnt work.

i was just wondering, what way do i need to go to be able to get the function(s) from my other addon???
  Reply With Quote
07-31-11, 11:00 PM   #2
barbol12
A Cyclonian
 
barbol12's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2010
Posts: 42
nvm ignore post... i got it figured out, just needed to make an engine duh!
  Reply With Quote
07-31-11, 11:02 PM   #3
Mischback
A Cobalt Mageweaver
 
Mischback's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 221
The functions have to be global.

Usually best way is to create functions like this:

local function bla(blubb)

but you need

function YOUR_ADDON_bla(blubb)

I would advise you, to prefix the functions with your addon's name, to make sure they are unique in the global namespace. Otherwise you could taint other addons or even the WoW-API-functions. Just as it is good practice with global variables.
__________________
  Reply With Quote
08-01-11, 12:19 AM   #4
barbol12
A Cyclonian
 
barbol12's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2010
Posts: 42
ya.. but i found an easy way around it all i just made an engine for my entire addon(s)
  Reply With Quote
08-01-11, 12:28 AM   #5
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
A tip, if you put for example this on top of the lua files in your addon:
local addonName, addonTable = ...

The addonName will be the addon name (folder) and addonTable is a table shared by the entire addon locally. Hence if you got several files loading and you in the first one define:
function addonTable:Test() end

Then this function can be called by the later lua files by doing addonTable:Test() of course. Note that this may strain performance if you call a function from a table many times at once, hence this is a bit better (I heard, not tested):
local Test = addonTable.Test
Now calling Test() a bunch of times should be as if the function was created using "function Test() end"

I am sure some of my friends will correct me if I am wrong. :P
  Reply With Quote
08-01-11, 02:13 AM   #6
Aftermathhqt
A Molten Giant
 
Aftermathhqt's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 784
Originally Posted by barbol12 View Post
ya.. but i found an easy way around it all i just made an engine for my entire addon(s)

Good example that i have for my UI


LUA Code:
  1. AftermathhUI = {}
  2.  
  3.  
  4. AftermathhUI.Func = ...... -- this function can be meantion in anywhere within your texts
  5.  
  6.  
  7. AftermathhUI["c"] = { -- this needs to be loaded before ANYTHING.
  8.  
  9.         ["mybordercolor"] = {.25, .25, .25}
  10.         ["disablemything"] = false,
  11.  
  12. }
  13.  
  14. local Frame = ("Frame", nil, UIParent)
  15. frame:SetBackdropColor(unpack(AftermathhUI.c.mybordercolor)) -- this unpacks the color
  16.  
  17. if AftermathhUI.c.disablemything == false then
  18.  
  19. .......
  20.  
  21. end

Hope this help you abit forward

Last edited by Aftermathhqt : 08-01-11 at 02:20 AM.
  Reply With Quote
08-01-11, 10:28 AM   #7
Mischback
A Cobalt Mageweaver
 
Mischback's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 221
Originally Posted by Vladinator View Post
A tip, if you put for example this on top of the lua files in your addon:
local addonName, addonTable = ...

The addonName will be the addon name (folder) and addonTable is a table shared by the entire addon locally. Hence if you got several files loading and you in the first one define:
function addonTable:Test() end

Then this function can be called by the later lua files by doing addonTable:Test() of course. Note that this may strain performance if you call a function from a table many times at once, hence this is a bit better (I heard, not tested):
local Test = addonTable.Test
Now calling Test() a bunch of times should be as if the function was created using "function Test() end"

I am sure some of my friends will correct me if I am wrong. :P
I pretty much do this everytime I feel I need to have several files..

File 1
lua Code:
  1. local ADDON, ns = ...
  2.  
  3. local settings = {}
  4.  
  5. settings.color = {
  6.     -- stuff here
  7. }
  8.  
  9. ns.settings = settings

File 2
lua Code:
  1. local ADDON, ns = ...
  2.  
  3. local settings = ns.settings
  4.  
  5. -- now I can use the settings (colors) here

However, he asked to have the function available in another addon, not in another file.

I would really like to know, what you mean by "engine" and how you go about it.
I had a similar problem some time ago (create one look throughout all my addons) and I go the way to create one addon which provides some functions to create borders and backgrounds and stuff and made the functions global.
__________________
  Reply With Quote
08-01-11, 03:10 PM   #8
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
For another addon you would have to use global variable, minimum one!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » functions from other addons

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