Quantcast Get the texture path from textureID? - WoWInterface
Thread Tools Display Modes
03-22-19, 09:05 AM   #1
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,081
Get the texture path from textureID?

I've been searching all over, knowing I missed something basic. I know the following returns the path to the texture, but only if you already know the texture's name, ie: it's a string.
Code:
local ActionBar1:GetTexture() -- should work
local 23571:GetTexture() -- (made up fileID) will this work?
What if the texture is a textureID, a number? How do you get its name and path? I'm going from Wowpedia's docs, so maybe GetTexture() works on numerical textureIDs, but I doubt it.

Last edited by myrroddin : 03-22-19 at 09:22 AM. Reason: better example
  Reply With Quote
03-22-19, 06:24 PM   #2
Kanegasi
A Scalebane Royal Guard
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 424
This is a part of Lua. GetTexture in this case is a method, a function as a value of a key in a table. ActionBar1 is a table set up with the methods of a standard frame. Frames are a WoW-specific thing, tables set up with a standard set of methods and a metatable.

Lua Code:
  1. ActionBar1 = {
  2.     GetTexture = function()
  3.         -- whatever code is here
  4.     end
  5. }

Using the following chat command will print the word "table" into your chat window:

/run print(type(ActionBar1))

And this will print the word "nil", which means you'll get an error if you try to use a method with it:

/run print(type(23571))

My suggestion would be to create a frame, create a texture with it, use SetTexture with the textureID, then use GetTexture on that frame. Here's the following steps to do this just from chat commands, one at a time:

Code:
/run TextureFinderFrame = CreateFrame("frame")
/run TextureFinderFrame:CreateTexture("TextureFinder")
/run TextureFinder:SetTexture(23571)
/run print(TextureFinder:GetTexture())
These commands were "dry coded", which means I have not tested these, but they should work.
  Reply With Quote
03-23-19, 09:59 AM   #3
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,081
That's a great solution. Make a temp frame, set the texture, get the texture path. Why didn't I think of that?
  Reply With Quote
03-23-19, 11:50 AM   #4
lightspark
A Rage Talon Dragon Guard
 
lightspark's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 328
Well, sometimes GetTexture() returns texture IDs, but other times it returns texture paths, whichever is available, I guess, you can't be 100% sure.

There's GetTextureFileID and GetTextureFilePath, however, they don't really work the way one'd expect them to work.

If you passed an ID to SetTexture, GetTextureFilePath will return the object itself O_o (I assume that's a bug, it should return nil, I'll report it on Monday), GetTextureFileID will return that ID, if you passed a path to SetTexture, GetTextureFileID will return nil, GetTextureFilePath will return that path.

There's this lovely thing though: https://www.townlong-yak.com/framexm...tTextureID.lua
__________________

Last edited by lightspark : 03-23-19 at 11:54 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Get the texture path from textureID?

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