WoWInterface

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

loff93 07-26-17 11:04 PM

Cache suggestions
 
Hello!

Example of my code:

Code:

local Immerseus_LFR = {
        [1] = 104922; -- Hood of swirling senses
}

Immerseus = {
        [1] = {unpack(Immerseus_LFR)};
}

Siege_Of_Orgrimmar = {
        [1] = {name = "Immerseus", unpack(Immerseus)};
}

When I click show items, it will go through the list and spawn the item name etc, but when the item isn't cached it won't show up. Currently I don't have a good way that refreshes/grabs all the items it's going to show.
Any suggestions/tips on how to solve this?
I can't have the addon caching every table when you login because it will be too many tables & data in the end (I assume), so a better way would be:
When you click the "raid". Cache the items -> show items.
Or
Have a "Grab Items" button that you click when you want to use the addon maybe(?)

Have used this for single items earlier but not quite sure how to tweak it for the best solution. I might find a good solution once I know the best way to deal with cache in this situation.
Not that experienced with LUA.
Code:

local wait = {}
local cache_writer = CreateFrame('Frame')
cache_writer:RegisterEvent('GET_ITEM_INFO_RECEIVED')
cache_writer:SetScript('OnEvent', function(self, event, ...)
    if event == 'GET_ITEM_INFO_RECEIVED' then
        -- the info is now downloaded and cached
        local itemID = ...
                local name = GetItemInfo(itemID)
        if wait[itemID] then
                        -- do something when ID is recieved
            wait[itemID] = nil
                        end
    end
end)

Function to show items:
Code:

function CreateItemList(Instance, Difficulty, newFrame)

Banknorris 07-27-17 07:22 PM

http://www.wowinterface.com/forums/s...ad.php?t=55352

loff93 07-27-17 07:29 PM

Quote:

Originally Posted by Banknorris (Post 324394)

Yes, I have read it ofcourse since it's my own thread from April and I have a solution in mind for my current project as written above - but a general answer on whats recommended for my project would be greatly appreciated. I can make things work etc, but I want the addon to be clean, low memory usage etc and I don't feel like I have a very good solution - but it might just be me overthinking it.
Can do my best and share the result, and get some input.

Kakjens 07-28-17 04:59 AM

I am using a check
Lua Code:
  1. if wait == {} then
  2. updatevisibility()
  3. end
to see when all items are ready. I remember it failed sometimes but couldn't reproduce after clearing the cache.

loff93 07-28-17 05:30 AM

Quote:

Originally Posted by Kakjens (Post 324397)
I am using a check
Lua Code:
  1. if wait == {} then
  2. updatevisibility()
  3. end
to see when all items are ready. I remember it failed sometimes but couldn't reproduce after clearing the cache.

Cool, thanks for the input :)

Banknorris 07-28-17 11:22 AM

Quote:

Originally Posted by Kakjens (Post 324397)
I am using a check
Lua Code:
  1. if wait == {} then
  2. updatevisibility()
  3. end
to see when all items are ready. I remember it failed sometimes but couldn't reproduce after clearing the cache.

I am pretty sure
Code:

wait=={}
is always false
just test
Lua Code:
  1. local a={}
  2. if a=={} then
  3.     print("Bank Norris is wrong")
  4. else
  5.     print("Bank Norris is correct")
  6. end

SDPhantom 07-28-17 02:40 PM

Explaining why, {}=={} is not doing anything special to compare values in tables. What it does is create two completely different tables and compare their pointers. Since they are exactly two different tables, their pointers are different and this results in false. If you want to check if the table is empty, the most basic way is to call next(wait) and see if it returns nil.


All times are GMT -6. The time now is 02:19 PM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI