• 0

    posted a message on GetItemInfo, servercache and localcache
    As far as i know that event can be triggered more then once when you use SetHyperlink. I am pretty sure that for example Patterns that craft an item trigger it twice - once for the pattern and once for the item they craft.

    So if you were to request the tooltip for a LWing recipe and it triggered two responses, you would end up removing an entry from the table that you actually didnt get the response for yet.
    Posted in: Lua Code Discussion
  • 0

    posted a message on GetItemInfo, servercache and localcache
    Don't think your code is entirely correct. The first item that gets querried is at the start of the table, but if you receive the tooltip from the server you take the last entry from the tables, which did not get polled yet. But then you continue polling items always from the end of the table, so from then on it would be correct. I changed it so it kindo works like FIFO

    local ttframe
    
    function FLS:CacheItem(itemLink,slot)
        if not ttframe then
            ttframe = CreateFrame("GameTooltip", nil, nil, "GameTooltipTemplate")
            ttframe:SetOwner(UIParent, "ANCHOR_NONE")
            ttframe:SetScript('OnTooltipSetItem', function(self) FLS:OnTooltipSetItem(self) end)
            ttframe.slots = {}
            ttframe.itemLinks = {}
            ttframe:SetHyperlink(itemLink)
        elseif not next(ttframe.slots) then
            ttframe:SetHyperlink(itemLink)
        end
        tinsert(ttframe.slots, slot)
        tinsert(ttframe.itemLinks, itemLink)
    end
    
    function FLS:OnTooltipSetItem(tootlip)
        local itemLink = table.remove(tooltip.itemLinks,1)
        local slot = table.remove(tooltip.slots,1)
        if GetItemInfo(itemLink) then
            local name, link, quality, iLevel, reqLevel, type, subType, maxStack, equipSlot, texture = GetItemInfo(itemLink)
            currentloot[slot].item = name
            currentloot[slot].quality = quality
            currentloot[slot].texture = texture
            self:UpdateSlaveFrameSlot(slot)
        end
        if next(ttframe.itemlinks) then
            ttframe:SetHyperlink(next(ttframe.itemlinks))
        end
    end


    This of corse will only work if OnTooltipSetItem is only triggered when the tooltip is finally received from the server and not by some intermediate responses. Thus this version seems saver to me:

    local ttframe
    
    function FLS:CacheItem(itemLink,slot)
        if not ttframe then
            ttframe = CreateFrame("GameTooltip", nil, nil, "GameTooltipTemplate")
            ttframe:SetOwner(UIParent, "ANCHOR_NONE")
            ttframe:SetScript('OnTooltipSetItem', function(self) FLS:OnTooltipSetItem(self) end)
            ttframe.slots = {}
            ttframe.itemLinks = {}
            ttframe:SetHyperlink(itemLink)
        elseif not next(ttframe.slots) then
            ttframe:SetHyperlink(itemLink)
        end
        tinsert(ttframe.slots, slot)
        tinsert(ttframe.itemLinks, itemLink)
    end
    
    function FLS:OnTooltipSetItem(tootlip)
      local itemName, itemLink = tooltip:GetItem()
      if GetItemInfo(itemLink) then
        local i = table.findElement(tootlip.itemLinks, itemLink)
        if i then
          local slot = tootlip.slots[i]
          local name, link, quality, iLevel, reqLevel, type, subType, maxStack, equipSlot, texture = GetItemInfo(itemLink)
          currentloot[slot].item = name
          currentloot[slot].quality = quality
          currentloot[slot].texture = texture
          self:UpdateSlaveFrameSlot(slot)
          table.remove(tootlip.itemLinks, i)
          table.remove(tootlip.slots, i)
          if next(ttframe.itemlinks) then
            ttframe:SetHyperlink(next(ttframe.itemlinks))
          end
        end
      end
    end


    Obviously table.findElement is a selfdefined function that finds the index of an element.
    Posted in: Lua Code Discussion
  • 0

    posted a message on GetItemInfo, servercache and localcache
    Halting execution to receive tooltip, don't know if its a good idea. It would fetch the item data one by one adding up to a huge delay when displaying multiple items. The solution i use now is using like a maximum of 5 tooltip frames (don't think any boss drops more then 5 epic items) that all get re-used.
    Posted in: Lua Code Discussion
  • 0

    posted a message on GetItemInfo, servercache and localcache
    I am aware that this creates many frames that will never be garbage collected. But my addon displays all the drops at the same time, so it will have to collect multiple items at the same time. I am not sure how SetHyperlink will behave when I call it multiple times for the same Tooltip-Frame on different items in quick succession. Will it send a response for every item, or only the latest one?

    local ttframes = {}
    
    function FLS:CacheItem(itemLink,slot)
      if not ttframes[slot] then
        ttframes[slot] = CreateFrame("GameTooltip", nil, nil, "GameTooltipTemplate")
      end
      local ttframe = ttframes[slot]
      ttframe:SetOwner(UIParent, "ANCHOR_NONE")
      ttframe:SetScript('OnTooltipSetItem', function() FLS:OnTooltipSetItem(itemLink,slot) end)
      ttframe:SetHyperlink(itemLink)
    end
    


    But i guess i can change the function to this?
    Posted in: Lua Code Discussion
  • 0

    posted a message on GetItemInfo, servercache and localcache
    I think i found a solution and will test it in the next raid. Basically i call CacheItem if GetItemInfo returns nil. This function creates a tooltip and an event listener for when the tooltip is received. When the Tooltip is received GetItemInfo is called again and the frame is updated at the affected slot.

    function FLS:CacheItem(itemLink,slot)
      local ttframe = CreateFrame("GameTooltip", nil, nil, "GameTooltipTemplate")
      ttframe:SetOwner(UIParent, "ANCHOR_NONE")
      ttframe:SetScript('OnTooltipSetItem', function() FLS:OnTooltipSetItem(itemLink,slot) end)
      ttframe:SetHyperlink(itemLink)
    end
    
    function FLS:OnTooltipSetItem(itemLink,slot)
      if GetItemInfo(itemLink) then
        local name, link, quality, iLevel, reqLevel, type, subType, maxStack, equipSlot, texture = GetItemInfo(itemLink)
        currentloot[slot].item = name
        currentloot[slot].quality = quality
        currentloot[slot].texture = texture
        self:UpdateSlaveFrameSlot(slot)
      end
    end
    Posted in: Lua Code Discussion
  • 0

    posted a message on GetItemInfo, servercache and localcache
    I have a similar problem in a similar addon.

    My addon sends the dropped loot over acecomm to everyone with the same addon. They then get a popup to need/greed/pass on all the loot. I send hte items via itemlink not itemid. In the client side opopup you can see the item icon, name and tooltip on mouseover. But i still get reports that some people have no texture/name/tooltip for the item that dropped (They see only the questionmark icon i guess).

    So I am wondering how is this possible if I send the item link in the acecomm message? Aparently itemlinks in an acecomm message does not make the client cache the item locally. From my experience it only works in messages the client user can actually see (like in raid chat). So far I could avoid this bug by linking all drops in raid chat before making the window pop up client side. This is obviously not an ideal fix to the problem.

    I know i can force the item into the local cache by using GameTooltip:SetHyperlink. But this method doesn't halt execution and wait for the item to get loaded. So most likely GetItemInfo will still return only nils if used a few lua lines later.

    Here is the code i use client side:
    local name, link, quality, iLevel, reqLevel, type, subType, maxStack, equipSlot, texture = GetItemInfo(itemLink)
      -- force the item into the cache
    if name == nil then
      GameTooltip:SetHyperlink(itemLink)
      name, link, quality, iLevel, reqLevel, type, subType, maxStack, equipSlot, texture = GetItemInfo(itemLink)
    end
    


    So i suppose i have to add an event listener for when i receive the data back from the server? How would i proceed about doing that?
    Posted in: Lua Code Discussion
  • To post a comment, please or register a new account.