I chose CollapseAll and SetRollExpanded because I’ve done a few of these on other frames and always used seperate buttons to collapse and expand, a single toggle button would work just as well but I can’t seem to make that work yet either. I think the bigger problem is tables (which I’ll get to in a second)
I got the button frames setup and for the function so far I’ve got:
This returns “attempt to call method ‘LootHistoryFrame_CollapseAll’ (a nil value)” and I’m guessing it’s because I haven’t setup the table of items on the Loot history list correctly, I can’t seem to get it right with:
C_LootHistory:expandedRolls and C_LootHistory:GetItem
I have very little experience in programming and have mostly just done basic function calls. Not very good with tables and I’m kind of lost on where to go from here with this. Any help would be much appreciated.
I had previously tried LootHistoryFrame_CollapseAll(self), but this said self was a nil value and that was when I eventually ended up with what I posted.
This has at least stopped the error while testing with an empty list. I’ll try it out tonight after the Loot history frame has stuff in it so I can see if it is hiding/showing the rolls.
Does “self” normally have to be changed to the frame name? or do I have to set it as a variable name or something like that? such as
SetScript("OnClick", function()
local self = LootHistoryFrame
LootHistoryFrame_CollapseAll(self)
end)
I know this just does the same thing as yours, just trying to understand. feels like I see (self) or () used alot but maybe I am misunderstanding its use.
The purpose of self tends to vary depending on developer but in scripts like OnClick the script is passed various paramers the first of which is the frame (button etc.) it"self". self in this case is just a name that could be anything (frame, button etc.) but self is most commonly used. OnClick also get two others, button and down.
Ok, I think I get that…using self made the function run on my button frame rather than the parent frame, in which case I have to specifically name the frame to run the function on.
Had time to test it tonight and the collapse button seems to be working correctly, however The expand one is not. When pressed it does nothing visually, but it does break the +/- button next to each item. No lua error pops up or anything like that, they just stop doing anything. after reload they are fine until I hit the expand I added.
ExLH:SetScript("OnClick", function()
function LootHistoryFrame_SetRollExpanded(LootHistoryFrame, rollID, isExpanded)
end
end)
This is what appeared to do nothing, While messing around with it I got errors like “Table index is nil” and bugsack showed the locals rollID and expandedRolls as nil.
ExLH:SetScript("OnClick", function ()
for i = 1,C_LootHistory.GetNumItems() do
function LootHistoryFrame_SetRollExpanded(LootHistoryFrame, rollID, isExpanded)
end
end
end)
This is where I am now but haven’t tried it out. I don’t think it will work because rollID and isExpanded need values. I think isExpanded gets true/false and rollID comes from C_LootHistory:GetItems or GetNumItems, but as I said I get lost dealing with tables.
ExLH:SetScript("OnClick", function()
function LootHistoryFrame_SetRollExpanded(LootHistoryFrame, rollID, isExpanded)
end
end)
When you put function or local function at the beginning of a line you are declaring (creating) a new function. (with the local declaration, the function is “valid” in the chunk of code it was created. Without local it is global (any addon can use it)
The above, effectively overwrites the Blizzard LootHistoryFrame_SetRollExpanded with the function you created which does nothing.
Like self, rollID and isExpanded are parameter names that the function uses to distinguish the different parameters. They could be names like param1, param2, param3 but that’s not very easy to understand what’s goin on. Your function doesn’t have these varialbles defined so they are always going to be passed as nil.
But, is any of this what you really want to do (expand the list to a specific rollId which you would have to know in advance) or are you just trying to show/hide the LootHistoryFrame?
The latter would easily be done with a single button.
I am using ToggleLootHistoryFrame in a macro to help troubleshoot this while I’m working on it. Its not part of the addon though.
What I wanted to do was use a single Collapse All button as it is faster than scrolling through all the rolls on the list to find what I’m looking for. This much is working.
I also wanted to include an “Expand all” button which just does the opposite of the collapse all. I thought it was going to be a quick thing but it has gotten more complicated than I was hoping.
I may just stick with collapse only for this frame and maybe experiment more another time. Expanding the ones I want to look at individually is still better than scrolling the whole list to find them.
ExLH:SetScript("OnClick", function()
local numItems = C_LootHistory.GetNumItems()
if numItems then
for i=1, numItems do
local rollID, itemLink, numPlayers, isDone, winnerIdx = C_LootHistory.GetItem(i)
LootHistoryFrame_SetRollExpanded(LootHistoryFrame, rollID, true)
end
end
LootHistoryFrame:Show()
end)
This is actually really close to something I tried last night but I think I had the "local"s outside the setscript which I’m guessing would have made things wierd.
It is giving an error when logging in
<name> or '...' expected near 'true'
I’ve changed true to … and the error is gone (Should this have been i or is … ok?). Also not getting any nil errors when I hit the button on an empty list so definitely progress.
It’s a bit hard to tell without the entire code (button, SetScript and all) that calls the function and an indication of the line the error is calling out.
--LootHistory Button-Expand
local ExLH = CreateFrame("Button", "Expand Loot", LootHistoryFrame, 'UIPanelButtonTemplate')
--Set frame strata to draw over most other frames
ExLH:SetFrameStrata(HIGH)
ExLH:SetFrameLevel(100)
ExLH:SetNormalTexture("Interface\\Buttons\\UI-PlusButton-Up")
--Set Attributes for button (i.e. size, anchor, text)
ExLH:SetSize(20,20)
ExLH:SetPoint("TOPRIGHT", -40,0)
ExLH.tooltipText = "Expand"
--Make button work with left click and execute Expand
ExLH:RegisterForClicks("LeftButtonUp")
ExLH:SetScript("OnClick", function ()
local numItems = C_LootHistory.GetNumItems()
if numItems then
for i = 1,numItems do
local rollID, itemLink, numPlayers, isDone, winnerIdx, isMasterLoot, isCurrency = C_LootHistory.GetItem(i)
function LootHistoryFrame_SetRollExpanded(LootHistoryFrame, rollID, ...)
end
end
LootHistoryFrame:Show()
end
end)
The error is
2x Interface\FrameXML\Bindings.xml:1 CollapseQuestLog/Main.lua:1 CollapseQuestLog/Main.lua:268: <name> or '...' expected near 'true'
Line 268 is the setrollexpanded line :
function LootHistoryFrame_SetRollExpanded(LootHistoryFrame, rollID, true)
Changed to
function LootHistoryFrame_SetRollExpanded(LootHistoryFrame, rollID, ...)
Adding function in front of LootHistoryFrame_SetRollExpanded is causing the error because you want to call the function, not create it. That and because your not creating the function you don’t need the extra end statement.
ExLH:SetScript("OnClick", function ()
local numItems = C_LootHistory.GetNumItems()
if numItems then
for i = 1,numItems do
local rollID, itemLink, numPlayers, isDone, winnerIdx, isMasterLoot, isCurrency = C_LootHistory.GetItem(i)
LootHistoryFrame_SetRollExpanded(LootHistoryFrame, rollID, true)
end
end
LootHistoryFrame:Show()
end)