WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Bag Lua Problem (https://www.wowinterface.com/forums/showthread.php?t=33683)

hairy_palms 07-03-10 08:05 AM

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.

xConStruct 07-03-10 08:49 AM

Code:

local closesackframe = CreateFrame("FRAME2", "closemysack");
"FRAME2" is not a valid widget type. You meant "Frame" here.

hairy_palms 07-03-10 09:05 AM

ah thanks a bunch :) knew i'd done something silly

hairy_palms 07-04-10 10:13 AM

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);


hairy_palms 07-04-10 10:52 AM

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)


hairy_palms 07-04-10 04:36 PM

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


Torhal 07-04-10 04:42 PM

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.

Vrul 07-04-10 06:46 PM

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


hairy_palms 07-05-10 06:28 AM

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 :o 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

Vrul 07-05-10 12:47 PM

Quote:

Originally Posted by hairy_palms (Post 195955)
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.


All times are GMT -6. The time now is 01:46 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI