Hi,
I wrote the following codes to check the amount of completed artifact for each races.
Lua Code:
local b = CreateFrame("Button", nil, UIParent, "OptionsButtonTemplate")
b:RegisterEvent("PLAYER_LOGIN")
b:SetPoint("TOP", 0, -100)
b:SetText(GetArchaeologyInfo())
b:SetScript("OnEvent", function(self, event, ...)
if event == "PLAYER_LOGIN" then
self:UnregisterEvent("PLAYER_LOGIN")
if not IsAddOnLoaded("Blizzard_ArchaeologyUI") then
LoadAddOn("Blizzard_ArchaeologyUI")
end
end
end);
b:SetScript("OnClick", function()
ArchaeologyFrameCompletedButton:Click()
local totalCompletion = 0
for i = 1, GetNumArchaeologyRaces() do
local j = GetNumArtifactsByRace(i)
local raceName = GetArchaeologyRaceInfo(i)
local currentCompletion = 0
for k = 1, j do
local _, _, _, _, _, _, _, _, completionCount = GetArtifactInfoByRace(i, k)
currentCompletion = currentCompletion + completionCount
end
totalCompletion = totalCompletion + currentCompletion
if j > 1 then
print(string.format("\124cffffff00%s:\124r %d", raceName, currentCompletion))
end
end
print("======================")
print(string.format("\124cffffff00Total:\124r %d", totalCompletion))
end)
The problem is that it prints an incorrect data on its initial click, then if I click the button again, it starts to print a correct amount.
I don't get where I'm doing it wrong
edit: Same behavior occurs after pressing solve button