View Single Post
04-07-22, 10:35 AM   #3
PARRYHOTTEr
A Defias Bandit
Join Date: Apr 2022
Posts: 3
Originally Posted by Fizzlemizz View Post
You need to wait until the game knows something about the characther you just logged in to, try (your code didn't mention where the frame is anchored so I made that bit up):
Lua Code:
  1. frame:SetSize(5, 5)
  2. frame:SetPoint("LEFT", 10, 0)
  3. frame.ilvlText = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  4. frame.ilvlText:SetPoint("TOPLEFT", 10, -60)
  5. frame:RegisterEvent("PLAYER_LOGIN")
  6. frame:RegisterUnitEvent("UNIT_INVENTORY_CHANGED", "player")
  7. frame:SetScript("OnEvent", function(self)
  8.     local avgItemLevel, avgItemLevelEquipped, avgItemLevelPVP = GetAverageItemLevel()
  9.     self.ilvlText:SetText("Average equipped ilvl is: " .. tostring(avgItemLevelEquipped or "Refresh UI"))
  10. end)
First of all thanks for the provided code, it works now!

In hindsight, i probably should've explained that i'm creating a simple character panel as a first addOn project and the 'frame' is a simple CreateFrame("Frame", nil, UIParent, "BackdropTemplateMixin" and "BackdropTemplate").

You mention that the game has to 'know' something about the character before it can read values about the character, etc; could you perhaps elaborate a little bit on that? If you have an article or something explaining it, that is also fine
  Reply With Quote