View Single Post
10-22-13, 04:26 PM   #1
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Got an issue with using a For loop to create frames

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:
  1. local infoSet = {
  2.     infoFrame = {info1, info2, info3, info4},
  3.     imageAnchor = {Image1, Image2, Image3, Image4},
  4.     button = {button1, button2, button3, button4},
  5. }    
  6.  
  7. for i = 1, 4 do
  8.     local infoBox
  9.     infoBox = infoSet.infoFrame[i]
  10.     infoBox = CreateFrame("Frame")
  11.     infoBox:SetSize(420, 90)
  12.     infoBox:SetPoint("BOTTOMLEFT", infoSet.imageAnchor[i], "BOTTOMRIGHT", -12, 3.5)
  13.     infoBox:SetFrameStrata("TOOLTIP")
  14.     infoBox:SetFrameLevel("16")
  15.     infoBox:SetBackdrop(Artwork_Import.infoBox)
  16.    
  17.     local button = infoSet.button[i]
  18.     button = CreateFrame("Button")
  19.     button:SetSize(80, 24)
  20.     button:SetPoint("BOTTOMRIGHT", infoBox, "BOTTOMRIGHT", -12, 10)
  21.     button:SetFrameStrata("TOOLTIP")
  22.     button:SetFrameLevel("17")
  23.     button:SetBackdrop(Artwork_Import.enableButton)
  24.     button:SetBackdropBorderColor(0.2,0.2,0.2)
  25. end
  26.  
  27. infoSet.infoFrame[1]:SetScript("OnShow", function(self)
  28.     self:SetScript("OnShow", nil)
  29.     self.text = self:CreateFontString(nil, "OVERLAY")
  30.     self.text:SetPoint("CENTER", self, "CENTER")
  31.     self.text:SetFont(FONT, 10)
  32.     self.text:SetText(TEXT.BottomChat)
  33.     self.text:SetTextColor(classcolor.r, classcolor.g, classcolor.b)
  34. end)

Last edited by Mayron : 10-23-13 at 03:24 AM.
  Reply With Quote