Thread Tools Display Modes
01-14-24, 01:08 PM   #1
TJones1467
A Defias Bandit
Join Date: Jan 2024
Posts: 2
New to Addons : Issue with SetTexture

I am new to LUA and creating addons, but I am not new to programming in general. I am working on an extremely simple addon to begin to figure things out. All I am trying to do at the moment is create a big red box in the middle of the game screen. Here is the code I have.

Code:
SLASH_RELOADUI1 = "/rl"
SlashCmdList.RELOADUI = ReloadUI

SLASH_FRAMESTK1 = "/fs"
SlashCmdList.FRAMESTK = function()
    LoadAddOn("Blizzard_DebugTools")
    FrameStackTooltip_Toggle()
end

local testFrame = CreateFrame("Frame", testFrame, UIParent)
testFrame:SetPoint("CENTER")
testFrame:SetSize(300,300)

local testFrame.texture = testFrame:CreateTexture()
testFrame.texture:SetAllPoints(testFrame)
testFrame.texture:SetTexture(255,0,0,0.5)
The first two slash commands are (probably obviously) just to help reload the UI and open the frame stack.

As far as I can tell, this should work. When I take a look at the frame stack, the frame is there but it isn't showing anything. I've included a link below to a screenshot of what I see with frame stack activated. I have bug grabber installed and it shows no errors.

https://www.dropbox.com/scl/fi/v9q5h...f5k11dnwa&dl=0

If anyone could point out what I am doing wrong here, I would greatly appreciate it.

Last edited by TJones1467 : 01-14-24 at 01:11 PM.
  Reply With Quote
01-14-24, 02:34 PM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
Install BugGrabber and BugSack to help with debugging. They work together.

You should be getting an error
Code:
local testFrame = CreateFrame("Frame", testFrame, UIParent)
is fine

Code:
local testFrame.texture = testFrame:CreateTexture()
is not fine. This second local is trying to create a new testFrame variable and .texture is trying to assume it is already a table (which it isn't).

Use:
Code:
testFrame.texture = testFrame:CreateTexture()
The first testFrame is a table (because frames are tables) so this should work.

That and
Code:
testFrame.texture:SetColorTexture(1,0,0,0.5)
SetTexture sets the texture file (name on disk) or file ID and WoW colours are 0 to 1. SetColorTexture creates a solid texture and colours it in one step.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 01-14-24 at 02:53 PM.
  Reply With Quote
01-14-24, 03:44 PM   #3
TJones1467
A Defias Bandit
Join Date: Jan 2024
Posts: 2
so, just to make sure I'm understanding this correctly. Please excuse my .Net (i know.. i know..) terminology.

the syntax testFrame.texture = testFrame:CreateTexture() is using the texture property of the testFrame (table) and then creating the texture to be applied to that property. is that right?

If that is correct, then I completely understand why it wasn't working. Thank you!

Last edited by TJones1467 : 01-14-24 at 05:14 PM.
  Reply With Quote
01-14-24, 05:21 PM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
Any time you see local in front of a variable name, you're creating a new variable (type to be determined on the other side of the =).

Code:
local testFrame = CreateFrame("Frame", testFrame, UIParent)
Creates a new Frame and assigns it to the testFrame variable of type table (as previously noted, frames are tables)

Lua Code:
  1. testFrame.texture = testFrame:CreateTexture()
Creates a new texture Region and assigns it the texture key of testFrame. Same as:
Lua Code:
  1. testFrame["texture"] = testFrame:CreateTexture()

But you can't add a key to a table that hasn't been created which is what
Code:
local testFrame.texture = testFrame:CreateTexture()
was trying to do (testFrame being nil at the time you get to the =).
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 01-14-24 at 05:45 PM.
  Reply With Quote
01-23-24, 10:17 PM   #5
dragonflyy
An Aku'mai Servant
 
dragonflyy's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 32
Originally Posted by TJones1467 View Post
so, just to make sure I'm understanding this correctly. Please excuse my .Net (i know.. i know..) terminology.

the syntax testFrame.texture = testFrame:CreateTexture() is using the texture property of the testFrame (table) and then creating the texture to be applied to that property. is that right?

If that is correct, then I completely understand why it wasn't working. Thank you!
local is part of the declaration, since you are familiar with .net this would be the same as trying to declare a variable twice with a type set, ie:

string value = "Something"
(some other code)
string value = "Nothing"

This would throw an exception, whereas if you wanted to change the value it would look more like:
string value = "Something"
(some other code)
value = "Nothing"

However, in Lua, variables are not typed, so we just declare if it's a local. If you don't add the local then it defaults as a global and is accessible inside all of WoW
  Reply With Quote
01-25-24, 05:01 AM   #6
ParrEsold
A Kobold Labourer
Join Date: Jan 2024
Posts: 1
Is your understanding of the syntax "testFrame.texture = testFrame:CreateTexture()" accurate, where it utilizes the texture property of the testFrame (table) and creates the texture to be applied to that property?
  Reply With Quote
01-25-24, 09:15 AM   #7
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
The .texture part is just making a table key, it could be anything. The :CreateTexture() creates the texture region and by using testFrame:CreateTexture() just means that testFrame will automatically be the parent of the new texture.

Code:
testFrame.SomethingToPutAPrettyPictureIn = testFrame:CreateTexture()
Same as
Code:
testFrame["SomethingToPutAPrettyPictureIn"] = testFrame:CreateTexture()
I get the feeling these days that some of the responses/questions in response seem like AI in training.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 01-25-24 at 10:09 AM.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » New to Addons : Issue with SetTexture


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