Thread Tools Display Modes
Prev Previous Post   Next Post Next
05-13-21, 10:21 PM   #1
Jokertito
A Murloc Raider
Join Date: Apr 2020
Posts: 5
How do you loop k,v pairs to create fontstrings?

Similar to this
Lua Code:
  1. local table = {"entry", "entry2", "entry3"}
  2.  
  3. for i = 1,20 do
  4.     local fsname = frame:CreateFontString(nil, "OVERLAY", "GameTooltipText")
  5.     fsname:SetPoint("TOPLEFT", frame, "TOPLEFT", 0, -10*(i-1))
  6.     fsname:SetText(table[i])
  7. end

But how do you do it for a table constructed like this

Lua Code:
  1. local table = {
  2.     ["entry"] = "One",
  3.     ["entry2"] = "Two",
  4.     ["entry3"] = "Three",
  5. }

So that when looped the fontstring comes out like this?

entry One
entry2 Two
entry3 Three

Thanks in advance

Edit: This is the method I found that works, if anyone knows a better way I'm all ears

Lua Code:
  1. local i = 1
  2. for k,v in pairs(table) do
  3.     local fsname = frame:CreateFontString(nil, "OVERLAY", "GameTooltipText")
  4.     fsname:SetPoint("TOPLEFT", frame, "TOPLEFT", 0, -10*(i-1))
  5.     fsname:SetText(k)
  6.  
  7.     local fsname2 = frame:CreateFontString(nil, "OVERLAY", "GameTooltipText")
  8.     fsname:SetPoint("TOPLEFT", frame, "TOPLEFT", 0, -10*(i-1))
  9.     fsname:SetText(v)
  10. end

I have this in a function a button calls so 'i' always starts as 1

Last edited by Jokertito : 05-14-21 at 12:13 AM.
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » How do you loop k,v pairs to create fontstrings?

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off