Thread Tools Display Modes
12-18-20, 01:55 PM   #1
Krainz
A Wyrmkin Dreamwalker
Join Date: Oct 2016
Posts: 57
Using SetTexture to change the texture of a frame created by another addon?

GwGarrisonButton is a frame created by GW2 UI

The goal with that code is to change gwbutton's texture to another one.

If I get it to work I'll start employing the same to other frames

Lua Code:
  1. UIMod_UpdateInterval = 0.3; -- How often the OnUpdate code will run (in seconds)
  2.  
  3.  
  4. f.TimeSinceLastUpdate = 0
  5.  
  6. f:SetScript("OnUpdate",function(self,elapsed)
  7.         local gwbutton = GwGarrisonButton
  8.         local garrisonType = C_Garrison.GetLandingPageGarrisonType()
  9.         local covenantID = C_Covenants.GetActiveCovenantID()
  10.     self.TimeSinceLastUpdate = self.TimeSinceLastUpdate + elapsed;
  11.  
  12.  
  13.     if (self.TimeSinceLastUpdate > UIMod_UpdateInterval) then
  14.         print("UIMOD OnUpdate");
  15.                 if gwbutton and gwbutton:IsShown() and gwbutton:IsVisible() and (covenantID ~= 0 or garrisonType == 111 or garrisonType == 3) then
  16.                         print("UIMOD OnUpdate: GW2 UI Garrison Button is shown. Editing texture.");
  17.                         gwbutton:SetTexture("Interface/AddOns/UIMod/textures/icon-1")
  18.                 end
  19.  
  20.  
  21.         self.TimeSinceLastUpdate = 0;
  22.         UIMod_UpdateInterval = 30.0;
  23.     end
  24. end)

However this returns me an error. Apparently I can't use SetTexture that way. I tried googling around but only found people talking about changing Blizzard's default textures.

How do I change the texture of a frame created by another addon?

Maybe a XML file could help in this case?
  Reply With Quote
12-20-20, 05:26 PM   #2
Krainz
A Wyrmkin Dreamwalker
Join Date: Oct 2016
Posts: 57
This is the error I'm getting:

Message: Interface\AddOns\UIMod\core.lua:58: attempt to call method 'SetTexture' (a nil value)
Time: Sun Dec 20 20:22:39 2020
Count: 768
Stack: Interface\AddOns\UIMod\core.lua:58: attempt to call method 'SetTexture' (a nil value)
[string "@Interface\AddOns\UIMod\core.lua"]:58: in function <Interface\AddOns\UIMod\core.lua:46>

Locals: self = <unnamed> {
0 = <userdata>
TimeSinceLastUpdate = 64.582002
}
elapsed = 0.016000
gwbutton = GwGarrisonButton {
0 = <userdata>
gw_Showing = true
gw_GarrisonType = 111
}
garrisonType = 111
covenantID = 0
(*temporary) = nil
(*temporary) = GwGarrisonButton {
0 = <userdata>
gw_Showing = true
gw_GarrisonType = 111
}
(*temporary) = "Interface/AddOns/UIMod/textures/icon-boss"
(*temporary) = "attempt to call method 'SetTexture' (a nil value)"
  Reply With Quote
12-20-20, 05:57 PM   #3
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
Buttons don't have a SetTexture method. You can only call SetTexture on an actual texture. However, buttons do have SetNormalTexture and SetPushedTexture methods for setting their visuals.
  Reply With Quote
12-20-20, 06:10 PM   #4
Krainz
A Wyrmkin Dreamwalker
Join Date: Oct 2016
Posts: 57
Using SetNormalTexture instead of SetTexture worked, thanks!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Using SetTexture to change the texture of a frame created by another addon?

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