Quantcast
One addon modifying another? - WoWInterface
Thread Tools Display Modes
12-13-20, 10:53 AM   #1
Krainz
A Wyrmkin Dreamwalker
Join Date: Oct 2016
Posts: 57
One addon modifying another?

I need to make my own addon that modifies a few others so that I don't have to modify their files every time they have an update.

So I went to look into how GW2 UI interacts with the Immersion addon:

Lua Code:
  1. local _, GW = ...
  2.  
  3. local function SkinImmersionAddonFrame()
  4.     local ImmersionFrame = _G.ImmersionFrame
  5.  
  6.     if ImmersionFrame then
  7.  
  8.         ImmersionFrame.TalkBox.BackgroundFrame.TextBackground:SetTexture("Interface/AddOns/GW2_UI/textures/party/manage-group-bg")
  9.  
  10.         ImmersionFrame.TalkBox.Hilite:Hide()
  11.  
  12.         ImmersionFrame.TalkBox.MainFrame.Indicator:SetPoint("TOPRIGHT", -56, -13)
  13.     end
  14. end
  15. GW.SkinImmersionAddonFrame = SkinImmersionAddonFrame

There are two things I don't understand in that code:

1. There is a local variable defined, ImmersionFrame. But what is _G.ImmersionFrame? I know that ImmersionFrame is a frame defined in the Immersion addon's XML files, but why the _G? What does it do?

2. The bit that says 'if ImmersionFrame then' checks if the ImmersionFrame exists, correct? How does the GW2 UI addon guarantee that it's going to overwrite what's originally stated in the Immersion addon?
  Reply With Quote
12-13-20, 11:21 AM   #2
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 814
_G represents the global namespace. So it takes the global one and makes it local.
The changes are made to both of them. (they are the same)
Probably you'll see that the toc-file makes sure the other Addon is loaded first.
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
12-13-20, 12:49 PM   #3
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,400
As an aside, the _G is not needed in this case because the frame name is added to the global table as a reference when the frame is created (all frames with names are added to the global table by default)

Lua Code:
  1. local ImmersionFrame = _G.ImmersionFrame
  2. --  is the same as:
  3. local ImmersionFrame = ImmersionFrame
  4. -- is the same as:
  5. local ImmersionFrame = _G["ImmersionFrame")
  6. -- is the same as (in ye olde addon speak):
  7. local ImmersionFrame = getglobal("ImmersionFrame")

Code:
if ImmersionFrame then
if the user doesn't have the Immersion addon, the frame won't exist so what comes after the "if" can be ignored.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 12-13-20 at 12:54 PM.
  Reply With Quote
12-13-20, 02:28 PM   #4
Krainz
A Wyrmkin Dreamwalker
Join Date: Oct 2016
Posts: 57
Originally Posted by Fizzlemizz View Post
As an aside, the _G is not needed in this case because the frame name is added to the global table as a reference when the frame is created (all frames with names are added to the global table by default)

Lua Code:
  1. local ImmersionFrame = _G.ImmersionFrame
  2. --  is the same as:
  3. local ImmersionFrame = ImmersionFrame
  4. -- is the same as:
  5. local ImmersionFrame = _G["ImmersionFrame")
  6. -- is the same as (in ye olde addon speak):
  7. local ImmersionFrame = getglobal("ImmersionFrame")

Code:
if ImmersionFrame then
if the user doesn't have the Immersion addon, the frame won't exist so what comes after the "if" can be ignored.
Oh, thanks for that explanation! It will make it much easier for me to understand what's going on

--

Is it possible to make something happen whenever a local function from another addon happens?

Like, when another addon (such as GW2 UI) makes the local funcion LoadMinimap() happen, is it possible to make my own addon do something?
  Reply With Quote
12-13-20, 02:37 PM   #5
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,400
Originally Posted by Krainz View Post
Is it possible to make something happen whenever a local function from another addon happens?
Not unless they've placed a reference to the local function (or calling function) in the global table or a call to the function in something globally accessable like a frame script.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 12-13-20 at 02:43 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » One addon modifying another?

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