Quantcast
WoWInterface - View Single Post - How do you loop k,v pairs to create fontstrings?
View Single Post
05-14-21, 11:17 AM   #5
Jokertito
A Murloc Raider
Join Date: Apr 2020
Posts: 5
This is all I wanted

Lua Code:
  1. local table = {
  2.     ["entry"] = "one",
  3.     ["entry2"] = "two",
  4.     ["entry3"] = "three",
  5. }
  6.  
  7. local f = CreateFrame("Frame", nil, UIParent, "BasicFrameTemplateWithInset")
  8. f:SetSize(250, 400)
  9. f:SetPoint("CENTER")
  10.  
  11. f.grabdata = CreateFrame("Button", nil, f, "SharedButtonTemplate")
  12. f.grabdata:SetText("G")
  13. f.grabdata:SetPoint("TOPLEFT", f, "TOPLEFT", 0, 0)
  14. f.grabdata:SetSize(40, 20)
  15. f.grabdata:SetScript("OnClick",
  16.     function()
  17.         local i = 0
  18.         for k,v in pairs(table) do
  19.             local fsname = f:CreateFontString(nil, "OVERLAY", "GameTooltipText")
  20.             fsname:SetPoint("TOPLEFT", f, "TOPLEFT", 9, -17*(i-(-2)))
  21.             fsname:SetText(k)
  22.            
  23.             local fsname2 = f:CreateFontString(nil, "OVERLAY", "GameTooltipText")
  24.             fsname2:SetPoint("TOPRIGHT", f, "TOPRIGHT", -10, -17*(i-(-2)))
  25.             fsname2:SetText(v)             
  26.             i = i + 1
  27.         end
  28.     end
  29. )



Click the "G" button and the data is presented.
  Reply With Quote