Hi all
I am trying to create an item list filter based on item rarity.
I have a scroll frame that populates a list of buttons based on a list of item hyperlinks; each of the scroll frame button print the item hyperlink to chat.
I have buttons to toggle boolean variables that I want to be able to filter the item hyperlinks however I have not been able to get them working properly; I am not getting any lua errors.
My first issue is that the scroll list requires multiple scrolls or update button clicks before the scroll buttons display correctly; they are there and they function correctly, they just do not display.
Is there a way to force them to display when the frame opens?
The second issue is the most important.
When I toggle a variable it does not seem to effect the list at all; I can manually change the rarity test function to force it to skip creating a button for items of that rarity, however it still builds the button it is now just not displaying.
How do I implement the item filter to correctly skip the button creation?
Here is a link to my lua;
https://pastebin.com/NUssNzMM
Here is a link to my toc;
https://pastebin.com/Uqu8pdSw
And here is a link to my gif showing the scroll and print issue;
https://imgur.com/TlS0SM5
Any help would be great
1 Like
HI all
I am still stumped with this one.
Any help would be fantastic.
1 Like
Not an indepth look or a comprehensive response but...
If the code linked is the code you are using, you should be getting at least one error if you have less items than 11 items in the SavedVariable list.
The updateScrollFrame function is looping the list 11 times even if there are less entries in the SavedVariables and passing nothing (nil or "") to testItemRarity() for the empty ones.
Your filter buttons set some text and a boolean value but they don't call any function to update the list updateScrollFrame() maybe?
There are some items in the ListOfItemRarity table and the filter but not set in the corresponding button(s).
After backing up: As well as adding updateScrollFrame() to the colour buttons, change the testItemRarity and updateScrollFrame functions too (this should filter out the button(s) selected ):
local function testItemRarity(itemToTestID)
local itemName, itemLink, itemRarity = GetItemInfo(itemToTestID)
if (ListOfItemRarity.rarityGrey and itemRarity == 0) or (ListOfItemRarity.rarityWhite and itemRarity == 1) or (ListOfItemRarity.rarityGreen and itemRarity == 2) or (ListOfItemRarity.rarityBlue and itemRarity == 3) or (ListOfItemRarity.rarityPurple and itemRarity == 4) or (ListOfItemRarity.rarityHeirloom and itemRarity == 5) or (ListOfItemRarity.rarityLegendary and itemRarity == 6) or (ListOfItemRarity.rarityArtifact and itemRarity == 7) then
return true
end
end
-- update scroll frames function
local listItems = {}
local function updateScrollFrame()
wipe(listItems)
for index = 1, #AAAGlobalItemLinkList do
if testItemRarity(AAAGlobalItemLinkList[index]) then
tinsert(listItems, AAAGlobalItemLinkList[index])
end
end
FauxScrollFrame_Update(testingScrollFrame, #listItems, NumberOfButtons, HeightOfButtons)
for index=1, NumberOfButtons do
local offset = index + FauxScrollFrame_GetOffset(testingScrollFrame)
local button = testingScrollFrame.buttons[index]
if index > #listItems then
button:SetText("")
button.index = nil
else
button.index = offset
button:SetText(listItems[offset])
end
end
end
You could initialise the list when the game starts (would need something different if the frame isn't created on load as it is now).
Add to the testingMainFrame setup
testingMainFrame:RegisterEvent("PLAYER_LOGIN")
testingMainFrame:SetScript("Onevent", function(self)
updateScrollFrame()
end)
The following code should be moved into the PLAYER_LOGIN event code just above, before updateScrollFrame() so you don't wipe it between sessions:
-- create item link list if it dosent already exist
if not AAAGlobalItemLinkList then
AAAGlobalItemLinkList = {}
end
2 Likes
Hi Fizzlemizz
Sorry for the late reply, RL got hectic.
You were right I had loaded out of date, and very broken, code to pastebin :(
Here are the links to the updated code;
lua - https://pastebin.com/zMxTtQk7
toc - https://pastebin.com/UH6XQss2
Your filter code chunk works perfectly and I can see what I was trying to dynamically filter from the direct list instead of building a new list using the filtered list.
I sill have a couple of questions that hopefully you can explain for me.
I notice you use
wipe(listItems) to clear the list instead of
listItems = {}I was unaware of the
wipe function and I wonder is it preferable to wipe instead of resetting the list
using ={} or is there no real difference other than personal preference?
Using the
"PLAYER_LOGIN" event to run the
updateScrollFunction() still does not fully display the list buttons so I still have to click the update button a few times before all the list buttons display correctly.
Is this a limitation that I just have to live with or is there a foolproof method I should be using?
Thanks for all of your help.
1 Like
Every time you see
SomeVar = {}
whether or not the {} contains anything, you have created a brand new table starting at a brand new memory address and SomeVar now contains a pointer to that new table. Any other variable that previously referenced SomeVar (AnotherVar = SomeVar) now points to the old table.
This also applies to tables within tables.
Wipe empties the contents of the current table.
You can change the Login code as per below. Every time GetItemInfo references an item that is not cached locally, your list will be refreshed when the GET_ITEM_INFO_RECEIVED event is recieved.
testingMainFrame:RegisterEvent("PLAYER_LOGIN")
testingMainFrame:RegisterEvent("GET_ITEM_INFO_RECEIVED")
testingMainFrame:SetScript(
"Onevent",
function(self, event)
-- create empty item list if one does not already exist
if event == "PLAYER_LOGIN" then
if not AAAGlobalItemLinkList then
AAAGlobalItemLinkList = {}
end
if #AAAGlobalItemLinkList > 0 then
updateScrollFrame()
end
return
end
updateScrollFrame()
end
)
This will update the list when any addon calls GetItemInfo on a non-cached item but, if it was a problem, you could probably build in a mechanism to limit the updates to only items you didn't get a return for the itemRarity.
2 Likes
Hi Fizzlemizz
Thanks for all of your advice and explanations.
1 Like