I'm in the process of creating my first addon and teaching myself lua... I'm not an expert by any means so any help would be appreciated.
The addon I'm creating is a simple mount collection log which mimics the functionality that simple armory mount collection shows. It lists all the obtainable mounts, categorizes them and marks off those you have collected.
I've managed to get the main GUI and functionality sorted but it's not performing consistently. Meaning sometimes when you initialize the addon, the entire lua table has not been processed leaving a lot mounts missing in the GUI.
This issue is less of a problem when there are no addons enabled, but happens a lot more when there are other addons enabled at the same time. The main function of the code is below, I imagine the problem is to do with how many loops there are.
Any help is appreciated. I can provide the entire files if need be.
Lua Code:
local mountFrames = {}
local collectableMounts = 0
--Creating a frame to place expansion content in.
--For each value section and category run this loop
for k,v in pairs(sectionNames) do
--Reset location of frames
local yTwo = -20
local xTwo = 20
local rowC = 0
local frameName = MCL:GetName()
--Cycle through each section and check if database entry matches any string.
for s = 1, #sectionStrings do
if v.name == sectionStrings[s] then
--If string matches a section then we loop through all categories for that section and create a frame.
for i = 1, #v.category do
local a = self:CategoryFrame(v.category[i], sections[s], xTwo, yTwo)
local rowC = 0
local x = 10
local y = -25
for b,n in pairs(mountList) do
if n.name == sectionStrings[s] then
for h,j in pairs(n) do
if j.name == v.category[i] then
if j.mounts then
local total = 0
local totalc = 0
for t = 1, #j.mountID do
if j.mountID[t] then
local _, _, icon, _, _, _, _, isFactionSpecific, faction, _, isCollected, ID = C_MountJournal.GetMountInfoByID(j.mountID[t])
if (isFactionSpecific == true and faction == playerFaction) or isFactionSpecific == false then
if rowC > 0 then
x = x+48
end
rowC = rowC+1
local mountFrame = self:CreateMountIcons("TOPLEFT", x, y, a, isCollected, icon)
collectableMounts = collectableMounts+1
table.insert(mountFrames, collectableMounts, mountFrame)
end
if isCollected == true then
totalc = totalc+1
totalCollected = totalCollected+1
if v.category[i] ~= "Blizzard Store" then
totalCollectedNoStore = totalCollectedNoStore+1
end
end
end
end
for t = 1, #j.mounts do
if C_MountJournal.GetMountFromItem(j.mounts[t]) then
local mountID = C_MountJournal.GetMountFromItem(j.mounts[t])
local _, _, _, _, isUsable, sourceType, _, isFactionSpecific, faction, _, isCollected, mountID = C_MountJournal.GetMountInfoByID(mountID)
if (isFactionSpecific == true and faction == playerFaction) or isFactionSpecific == false then
if rowC > 0 then
x = x+48
end
rowC = rowC+1
local mountFrame = self:CreateIcons("TOPLEFT", x, y, j.mounts[t], a, isCollected)
collectableMounts = collectableMounts+1
table.insert(mountFrames, collectableMounts, mountFrame)
if isCollected == true then
totalc = totalc+1
totalCollected = totalCollected+1
if v.category[i] ~= "Blizzard Store" then
totalCollectedNoStore = totalCollectedNoStore+1
end
end
local item, itemLink = GetItemInfo(j.mounts[t]);
mountFrame:SetScript("OnClick", function(self, button, down)
if (itemLink) then
print(itemLink)
end
end)
--This will determine when to start a new row of mounts. Currently set to 6 mounts per row.
if(rowC == 50) then
y = y-45
x = 10
rowC = 0
end
total = total+1
end
end
end
a.title:SetText(v.category[i].." ("..totalc.."/"..total..")")
end
end
end
end
end
yTwo = yTwo - 80
end
end
end
end