View Single Post
04-07-22, 10:10 AM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
Originally Posted by PARRYHOTTEr View Post
Hello everyone!

I'm very new to coding addOns to wow, and i've encountered a problem that annoys me.

Whenever i launch the game, GetAverageItemlevel() returns a nil value. If i then reload the UI it will then start to return the expected values.

What i wish to figure out is a way to stop this behaviour of where i have to reload the UI once before the addOn displays the expected value.

The following code is giving me this problem:

Code:
local ilvlText = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
ilvlText:SetPoint("TOPLEFT", 10, -60)
local avgItemLevel, avgItemLevelEquipped, avgItemLevelPVP = GetAverageItemLevel()
ilvlText:SetText("Average equipped ilvl is: " .. tostring(avgItemLevelEquipped or "Refresh UI"))
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)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote