WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Using SetTexture to change the texture of a frame created by another addon? (https://www.wowinterface.com/forums/showthread.php?t=58469)

Krainz 12-18-20 01:55 PM

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?

Krainz 12-20-20 05:26 PM

This is the error I'm getting:

Quote:

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)"

Vrul 12-20-20 05:57 PM

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.

Krainz 12-20-20 06:10 PM

Using SetNormalTexture instead of SetTexture worked, thanks!


All times are GMT -6. The time now is 03:42 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI