WoWInterface (
-   Lua/XML Help (
-   -   Get the texture path from textureID? (

myrroddin 03-22-19 09:05 AM

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.

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.

Kanegasi 03-22-19 06:24 PM

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:


/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.

myrroddin 03-23-19 09:59 AM

That's a great solution. Make a temp frame, set the texture, get the texture path. Why didn't I think of that?

lightspark 03-23-19 11:50 AM

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:

All times are GMT -6. The time now is 06:32 AM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI