CreateFrame - Two Frames?

I’m coming to start making my own Addon and I’ve run into something weird which I can’t find any threads explaining or even people having the same problem.

I have a simple addon that places a rectangular frame on the screen, adds an orange texture to it, and then makes it draggable. Right now, that’s all it does.

The weird part is that it keeps creating two displayed boxes, both draggable.

Box 1: Always appears in TOPLEFT, 0,0 where I create the frame.
Box 2: Always appears where I last dragged one of the frames to on the screen.

Both frames are being changed when I modify code. I added some debug in and it changes both of them. I changed the color and both changed. When the debug messages at startup go off, only one set is shown.

Am I missing something here?

Code:

local debug = true
local buffBox = CreateFrame("Frame", "BuffBoxFrame", UIParent)
local tex = buffBox:CreateTexture()

buffBox:SetFrameStrata("MEDIUM")
buffBox:SetWidth(128)
buffBox:SetHeight(64)
buffBox.texture = tex
tex:SetAllPoints()
if debug then
	print("Setting texture color");
end
tex:SetColorTexture(1.0,0.5,0)
if debug then
	print("Setting texture alpha");
end
tex:SetAlpha(1.0)
if debug then
	print("Setting location");
end
buffBox:SetPoint("TOPLEFT", 0, 0)
buffBox:SetMovable(true)
buffBox:EnableMouse(true)
if debug then
	print("Register for Drag");
end
buffBox:RegisterForDrag("LeftButton")
buffBox:SetScript("OnDragStart", function(self)
									self:StartMoving();
									if debug then
										print("Moving started");
									end
								end)
buffBox:SetScript("OnDragStop", function(self)
									buffBox:StopMovingOrSizing();
									if debug then
										print("Ending Move");
									end
								end
)
if debug then
	print("Show the frame");
end
buffBox:Show()

possibly the texture not being anchored to the frame so its moving independently

i think /fstack will show you the frame stack under the mouse so you can tell what the object is. typing it in again should turn it off (i think)

you probably want to anchor the texture to the frame anyway

1 Like

Is there more code in your actual addon than supplied here? What you have posted won’t create two frames on its own.

Or, do you have a second copy of the addon running under another folder or second copy of the .lua file listed in the .toc?

That’s the entire LUA file. I had an XML file initially but removed it.

One entry for the LUA file, one copy of the Addon. That’s what’s got me stumped. Plus when I change code like modifying the colour or text, both change, so there’s definitely not an old copy somewhere.

I thought I had with the

buffBox.texture = tex
tex:SetAllPoints()

What am I missing?

Replace the first two line:

local debug = true
local buffBox = CreateFrame("Frame", "BuffBoxFrame", UIParent)

with:

EloraellFrameCounter = EloraellFrameCounter or 0
EloraellFrameCounter = EloraellFrameCounter+1
local debug = true
local buffBox = CreateFrame("Frame", "BuffBoxFrame__"..EloraellFrameCounter, UIParent)
print("                        TESTING!!!!!", buffBox:GetName())

Check to see if you get two different fame names printed. If so, you have a duplicate frame being created somewhere. I would search for the file name in all the .toc and xml files) under your AddOns folder.

1 Like
<Ui xmlns="http://www.blizzard.com/wow/ui" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/..\FrameXML\UI.xsd">
  <Script File="WyvernETA.lua" />
</Ui>

Your question triggered a realisation. The XML file had had all the Frame stuff cut out of it, and I was thinking of it as “essentially empty”. However the Script File was still included in the XML, so when it ran, it ran the LUA file because it was in the TOC, then ran it again because of the XML.

Thanks for the help, I have it working just fine now, by removing the XML file from the TOC.

Now on to GameToolTip and then party scanning to work out what buffs I’m missing. (Building a Classic addon to check that I have enough buffs).