Thread Tools Display Modes
11-10-16, 06:43 AM   #1
frohanss
A Cyclonian
AddOn Author - Click to view addons
Join Date: Mar 2011
Posts: 40
Artifact DataText

hey,
been working on making a Datatext view for Artifact power.
Im currently stuck on it always giving a error on first time login.

Getting this:
Code:
Message: Interface\FrameXML\MainMenuBar.lua:126: Usage: GetCostForPointAtRank(rank)
Time: 11/10/16 13:34:11
Count: 1
Stack: [C]: in function `GetCostForPointAtRank'
Interface\FrameXML\MainMenuBar.lua:126: in function <Interface\FrameXML\MainMenuBar.lua:124>
Interface\AddOns\ViksUI\Datatext\Artifact.lua:24: in function <Interface\AddOns\ViksUI\Datatext\Artifact.lua:22>
Locals: (*temporary) = nil
Here is my lua:
Lua Code:
  1. local T, C, L, _ = unpack(select(2, ...))
  2. --------------------------------------------------------------------
  3. -- player Artifact
  4. --------------------------------------------------------------------
  5.  
  6. if C.datatext.Artifact and C.datatext.Artifact > 0 then
  7.     local _G = _G
  8.     local format = format
  9.     local HasArtifactEquipped = HasArtifactEquipped
  10.     local MainMenuBar_GetNumArtifactTraitsPurchasableFromXP = MainMenuBar_GetNumArtifactTraitsPurchasableFromXP
  11.     local C_ArtifactUI_GetEquippedArtifactInfo = C_ArtifactUI.GetEquippedArtifactInfo
  12.     local ARTIFACT_POWER = ARTIFACT_POWER
  13.  
  14.     local Stat = CreateFrame("Frame")
  15.     Stat:EnableMouse(true)
  16.     Stat:SetFrameStrata("BACKGROUND")
  17.     Stat:SetFrameLevel(3)
  18.  
  19.     local Text  = LBottom:CreateFontString(nil, "OVERLAY")
  20.  
  21.  
  22.     local function Update(self)
  23.         local itemID, altItemID, name, icon, totalXP, pointsSpent =  C_ArtifactUI_GetEquippedArtifactInfo()
  24.         local numPoints, artifactXP, xpForNextPoint = MainMenuBar_GetNumArtifactTraitsPurchasableFromXP(pointsSpent, totalXP)
  25.    
  26.         if C.datatext.Artifact >= 6 then
  27.             Text:SetTextColor(unpack(C.media.pxcolor1))
  28.             Text:SetFont(C.media.pxfontHeader, C.media.pxfontHsize, C.media.pxfontHFlag)
  29.         else
  30.             Text:SetTextColor(unpack(C.media.pxcolor1))
  31.             Text:SetFont(C.media.pixel_font, C.media.pixel_font_size, C.media.pixel_font_style)
  32.         end
  33.  
  34.         PP(C.datatext.Artifact, Text)
  35.         local showArtifact = HasArtifactEquipped();
  36.        
  37.         if not showArtifact then
  38.             Text:SetText("Artifact Not Equipped")
  39.         else
  40.         if C.datatext.Artifact >= 6 then
  41.         Text:SetText("|cffFFFFFF"..T.ShortValue(artifactXP).."/"..T.ShortValue(xpForNextPoint))
  42.         else
  43.         Text:SetText(qColor..T.ShortValue(artifactXP).."/"..T.ShortValue(xpForNextPoint))
  44.         end
  45.         self:SetAllPoints(Text)
  46.         end
  47.     end
  48.  
  49.     Stat:RegisterEvent("ARTIFACT_XP_UPDATE")
  50.     Stat:RegisterEvent("UNIT_INVENTORY_CHANGED")
  51.     Stat:RegisterEvent("PLAYER_LOG_IN")
  52.     Stat:RegisterEvent("PLAYER_ENTERING_WORLD")
  53.     Stat:SetScript("OnMouseDown", function() if not ArtifactFrame or not ArtifactFrame:IsShown() then ShowUIPanel(SocketInventoryItem(16)) elseif ArtifactFrame and ArtifactFrame:IsShown() then HideUIPanel(ArtifactFrame) end end)
  54.     Stat:SetScript("OnEvent", Update)
  55.     Stat:SetScript("OnEnter", function(self)
  56.         if not InCombatLockdown() then
  57.             GameTooltip:SetOwner(self, "ANCHOR_TOP", 0, 6);
  58.             GameTooltip:ClearAllPoints()
  59.             GameTooltip:SetPoint("BOTTOM", self, "TOP", 0, 1)
  60.             GameTooltip:ClearLines()
  61.             GameTooltip:AddLine(ARTIFACT_POWER)
  62.            
  63.             local itemID, altItemID, name, icon, totalXP, pointsSpent =  C_ArtifactUI_GetEquippedArtifactInfo();
  64.             local numPoints, artifactXP, xpForNextPoint = MainMenuBar_GetNumArtifactTraitsPurchasableFromXP(pointsSpent, totalXP);
  65.             GameTooltip:AddDoubleLine(qColor.."Equiped: "..name..", Level: "..pointsSpent)
  66.             GameTooltip:AddDoubleLine("XP:", format(' %d / %d (%d%%)', artifactXP, xpForNextPoint, artifactXP/xpForNextPoint * 100), 1, 1, 1)
  67.             GameTooltip:AddDoubleLine("Remaining:", T.ShortValue(xpForNextPoint-artifactXP), 1, 1, 1)
  68.             GameTooltip:Show()
  69.         end
  70.     end)
  71.     Stat:SetScript("OnLeave", function() GameTooltip:Hide() end)
  72. end



Everything seems to look as it should even with the error. It's just annoying, and i need to exit wow to get the error up again. As it doesn't show with simple reload ui or logout/login.

Any sugestions?
  Reply With Quote
11-10-16, 08:37 AM   #2
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
Your Update function does not check if artifact data has become available to the client prior to calling C_ArtifactUI.GetEquippedArtifactInfo().

Also, there is no event named PLAYER_LOG_IN, there is PLAYER_LOGIN. This is however useless in regard to artifact data.

You may also want to set your font outside the Update function, no need to reset it every time.

And I don't see any reason to duplicate code in your OnEnter script handler (which again does not check if an artifact is actually equipped). Just use the values you got from Update.
  Reply With Quote
11-10-16, 09:07 AM   #3
frohanss
A Cyclonian
AddOn Author - Click to view addons
Join Date: Mar 2011
Posts: 40
Originally Posted by Rainrider View Post
Your Update function does not check if artifact data has become available to the client prior to calling C_ArtifactUI.GetEquippedArtifactInfo().

Also, there is no event named PLAYER_LOG_IN, there is PLAYER_LOGIN. This is however useless in regard to artifact data.

You may also want to set your font outside the Update function, no need to reset it every time.

And I don't see any reason to duplicate code in your OnEnter script handler (which again does not check if an artifact is actually equipped). Just use the values you got from Update.
Thanks, got it fixed. Just needed some fresh eyes
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Artifact DataText


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off