Thread Tools Display Modes
07-03-10, 08:05 AM   #1
hairy_palms
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Feb 2010
Posts: 25
Bag Lua Problem

ive written an addon to try and open/close my bags when i go to the AH or mail or vendor, so far it works 50%, the bags open perfectly, but they dont close when i leave the vendor/AH, can anyone see where ive gone wrong?

Code:
--------------
--Opening
--------------
local opensackframe = CreateFrame("FRAME", "openmysack");

opensackframe:RegisterEvent("AUCTION_HOUSE_SHOW")
opensackframe:RegisterEvent("BANKFRAME_OPENED")
opensackframe:RegisterEvent("GUILDBANKFRAME_OPENED")
opensackframe:RegisterEvent("MAIL_SHOW")
opensackframe:RegisterEvent("MERCHANT_SHOW")
opensackframe:RegisterEvent("TRADE_SHOW")

local function openeventHandler(self, event, ...)
	OpenAllBags(true)
end
opensackframe:SetScript("OnEvent", openeventHandler);

--------------
--Closing
--------------

local closesackframe = CreateFrame("FRAME2", "closemysack");

closesackframe:RegisterEvent("AUCTION_HOUSE_CLOSED")
closesackframe:RegisterEvent("BANKFRAME_CLOSED")
closesackframe:RegisterEvent("GUILDBANKFRAME_CLOSED")
closesackframe:RegisterEvent("MAIL_CLOSED")
closesackframe:RegisterEvent("MERCHANT_CLOSED")
closesackframe:RegisterEvent("TRADE_CLOSE")

local function closeeventHandler(self, event, ...)
	CloseAllBags()
end
closesackframe:SetScript("OnEvent", closeeventHandler);
the CloseAllBags() never seems to get called.

Last edited by hairy_palms : 07-03-10 at 08:20 AM.
  Reply With Quote
07-03-10, 08:49 AM   #2
xConStruct
A Chromatic Dragonspawn
 
xConStruct's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 199
Code:
local closesackframe = CreateFrame("FRAME2", "closemysack");
"FRAME2" is not a valid widget type. You meant "Frame" here.
__________________
« Website | GitHub »

Oh hai!
  Reply With Quote
07-03-10, 09:05 AM   #3
hairy_palms
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Feb 2010
Posts: 25
ah thanks a bunch knew i'd done something silly
  Reply With Quote
07-04-10, 10:13 AM   #4
hairy_palms
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Feb 2010
Posts: 25
hopefully my next mistake is just as obvious

im trying to hide the backgrounds of the default backpacks, running the commands individually ingame as /script works fine, i thought i might be missing an event, but after 2 hrs browsing API documentation i cant see any events im missing. [EDIT]hmm it seems the BAG_OPEN isnt fireing it works on BAG_UPDATE.

Code:
------------
--Hide Bag Backgrounds
------------

local hiding = CreateFrame("Frame", "stealthbagz");
hiding:RegisterEvent("PLAYER_ENTERING_WORLD")
hiding:RegisterEvent("BAG_UPDATE")
hiding:RegisterEvent("BAG_OPEN")

local function hideBG(self, event, ...)
	for i = 1, NUM_CONTAINER_FRAMES do
		_G["ContainerFrame"..i.."CloseButton"]:Hide() -- works fine
		_G["ContainerFrame"..i.."BackgroundTop"]:Hide()
		_G["ContainerFrame"..i.."BackgroundBottom"]:Hide()
		_G["ContainerFrame"..i.."BackgroundMiddle1"]:Hide()
	end
end

hiding:SetScript("OnEvent", hideBG);

Last edited by hairy_palms : 07-04-10 at 10:38 AM.
  Reply With Quote
07-04-10, 10:52 AM   #5
hairy_palms
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Feb 2010
Posts: 25
ah i was making it harder than needed, didnt realise BAG_OPEN was deprecated, all i needed was

Code:
local function hideBG()
	ContainerFrame1MoneyFrame:Hide()
	for i = 1, NUM_CONTAINER_FRAMES do
		_G["ContainerFrame"..i.."CloseButton"]:Hide()
		_G["ContainerFrame"..i.."BackgroundTop"]:Hide()
		_G["ContainerFrame"..i.."BackgroundBottom"]:Hide()
		_G["ContainerFrame"..i.."BackgroundMiddle1"]:Hide()
	end
end
hooksecurefunc("ContainerFrame_OnShow", function() hideBG() end)
  Reply With Quote
07-04-10, 04:36 PM   #6
hairy_palms
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Feb 2010
Posts: 25
last problem i promise, im trying to anchor frames to open bags as i create them.
if i set it explicitly to ContainerFrame1 then it works,
but then all the frames are anchored to the same bag i want to anchor each frame to its respective bag, anyone see where ive gone wrong?

Code:
for i = 1, NUM_CONTAINER_FRAMES do
	local contname = "ContainerFrame"..i
	local bagbg = CreateFrame("Frame", bagbg, contname)--ContainerFrame1)--this is the problem
	bagbg:SetPoint("TOPRIGHT", contname, "TOPRIGHT", -5, -2)
	bagbg:SetPoint("BOTTOMLEFT", contname, "BOTTOMLEFT", 5, 0)	
	bagbg:SetBackdrop( { 
	  bgFile = BLANK_TEXTURE, 
	  edgeFile = BLANK_TEXTURE, 
	  tile = false, tileSize = 0, edgeSize = 1, 
	  insets = { left = -1, right = -1, top = -1, bottom = -1 }
	})
	bagbg:SetBackdropColor( 0.3,0.3,0.3,0.8)
end
  Reply With Quote
07-04-10, 04:42 PM   #7
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
Change this:

Code:
-- Change this
local bagbg = CreateFrame("Frame", bagbg, contname)

-- ...to this.
local bagbg = CreateFrame("Frame", nil, _G[contname])
In your current code, you're setting the global name of bagbg to something undefined. I set it to nil, because you'll probably not be accessing it globally. You're also attempting to parent it to a name (string), which isn't possible - I've changed it to actually parent to the globally-accessible frame of that name.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote
07-04-10, 06:46 PM   #8
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
You may want to reconsider how you are hiding the container components too. No need to keep hiding them over and over when you could just do it once. Also, there is more than one BackgroundMiddle texture to hide.

Code:
------------
--Hide Bag Backgrounds
------------

local function Hide(frame)
	frame:Hide()
	frame.Show = frame.Hide
end

for i = 1, NUM_CONTAINER_FRAMES do
	Hide(_G["ContainerFrame"..i.."CloseButton"])
	Hide(_G["ContainerFrame"..i.."BackgroundTop"])
	Hide(_G["ContainerFrame"..i.."BackgroundBottom"])
	for bg = 1, MAX_BG_TEXTURES do
		Hide(_G["ContainerFrame"..i.."BackgroundMiddle"..bg])
	end
end
  Reply With Quote
07-05-10, 06:28 AM   #9
hairy_palms
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Feb 2010
Posts: 25
that works great thx torhal, didnt realise you couldnt use a string.

@vrul, yeah that does work much better, i just dont understand how it works i tried hiding things once at first by just having
Code:
for i = 1, NUM_CONTAINER_FRAMES do
		_G["ContainerFrame"..i.."CloseButton"]:Hide()	
		_G["ContainerFrame"..i.."BackgroundTop"]:Hide()
		_G["ContainerFrame"..i.."BackgroundBottom"]:Hide()
		_G["ContainerFrame"..i.."BackgroundMiddle1"]:Hide()		
	end
does the hide function get associated with the containerframes and called on every frame.show in your code?
/learning

Last edited by hairy_palms : 07-05-10 at 08:53 AM.
  Reply With Quote
07-05-10, 12:47 PM   #10
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
Originally Posted by hairy_palms View Post
does the hide function get associated with the containerframes and called on every frame.show in your code?
All the frame.Show = frame.Hide does is make it so any time frame:Show() is run it will just do frame:Hide() instead.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Bag Lua Problem

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