I know there is something wrong with this code but I cannot figure out how to make it work. I want to create 4 frames that are nearly identical so I thought I could create them in a for loop but then I need to add different text to each frame as well as some script handlers like an OnClick script and more.. so I thought of making a for loop would be the right way to go but now I'm not sure. Should I just duplicate the code in the for loop 4 times for each frame and forget about the for loop or is there a way to make this work? The issue is that when I try to "SetScript("OnShow", function(self)" on a newly created frame from the for loop, it says it tries to index it as a nil value which does not surprise me either.
Thank you for reading
Lua Code:
local infoSet = {
infoFrame = {info1, info2, info3, info4},
imageAnchor = {Image1, Image2, Image3, Image4},
button = {button1, button2, button3, button4},
}
for i = 1, 4 do
local infoBox
infoBox = infoSet.infoFrame[i]
infoBox = CreateFrame("Frame")
infoBox:SetSize(420, 90)
infoBox:SetPoint("BOTTOMLEFT", infoSet.imageAnchor[i], "BOTTOMRIGHT", -12, 3.5)
infoBox:SetFrameStrata("TOOLTIP")
infoBox:SetFrameLevel("16")
infoBox:SetBackdrop(Artwork_Import.infoBox)
local button = infoSet.button[i]
button = CreateFrame("Button")
button:SetSize(80, 24)
button:SetPoint("BOTTOMRIGHT", infoBox, "BOTTOMRIGHT", -12, 10)
button:SetFrameStrata("TOOLTIP")
button:SetFrameLevel("17")
button:SetBackdrop(Artwork_Import.enableButton)
button:SetBackdropBorderColor(0.2,0.2,0.2)
end
infoSet.infoFrame[1]:SetScript("OnShow", function(self)
self:SetScript("OnShow", nil)
self.text = self:CreateFontString(nil, "OVERLAY")
self.text:SetPoint("CENTER", self, "CENTER")
self.text:SetFont(FONT, 10)
self.text:SetText(TEXT.BottomChat)
self.text:SetTextColor(classcolor.r, classcolor.g, classcolor.b)
end)