Thread Tools Display Modes
08-17-13, 09:20 AM   #1
SkyTwister
A Murloc Raider
Join Date: Aug 2013
Posts: 4
Question Calling a function from another addon

As per the above is this possible. I assume it is what with libraries etc being stand alone, but unsure if the specific functions needs to be detailed in a specific way for them to be available or not.

Reason I'm asking is I'm currently creating an addon to do something very specific for me with relation to pet battles (I may publish it eventually but it's more of a side project to introduce me to Lua etc). I'd like the ability to call on some of the functionality in another addon, PetBattleTeams, rather than reinventing the wheel and copying the functionality of PetBattleTeams into my own addon.

Have tried

NumTeams = TeamManager:GetNumTeams() but getting the 'attempt to index global "TeamManager" (a nil value)' error (to be fair I expected something like that to happen).

Also tried just NumTeams = GetNumTeams() with the error 'attempt to call global "GetNumTeams" (a nil value)'.

Function in PetBattleTeams is written like so:

Lua Code:
  1. function TeamManager:GetNumTeams()
  2.     return #self.teams
  3. end

I have also added it as a dependency (so it loads first).

Any help graciously appreciated and if you need more info let me know.

~SkyTwister
  Reply With Quote
08-17-13, 11:23 AM   #2
ckaotik
A Fallenroot Satyr
 
ckaotik's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 29
If you check TeamManager.lua, you'll notice that the TeamManager variable itself is declared in a file local scope.
Lua Code:
  1. local TeamManager = PetBattleTeams:NewModule("TeamManager")

You can access PetBattleTeams and probably use its function:
Lua Code:
  1. PetBattleTeams:GetModule("TeamManager")

You can then access GetNumTeams from there, like so:
Lua Code:
  1. local TeamManager = PetBattleTeams:GetModule("TeamManager")
  2. local numTeams = TeamManager:GetNumTeams()
__________________
It all starts to make a creepy kind of sense. Avatar

Last edited by ckaotik : 08-17-13 at 11:25 AM. Reason: Added Lua highlighting
  Reply With Quote
08-17-13, 03:14 PM   #3
SkyTwister
A Murloc Raider
Join Date: Aug 2013
Posts: 4
Perfect thanks

I'll add that to the list of things I'll look for in future.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Calling a function from another 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