Thread Tools Display Modes
01-23-16, 09:20 PM   #1
Lesteryoung
A Black Drake
Join Date: Aug 2015
Posts: 81
How do I merge these two tables?

Lua Code:
  1. local fontStrings = {
  2.     PlayerName,
  3.  
  4.     TargetFrameTextureFrameName,
  5.     TargetFrameTextureFrameDeadText,
  6.  
  7.     FocusFrameTextureFrameName,
  8.     FocusFrameTextureFrameDeadText
  9. }
  10.  
  11. for _, v in pairs(fontStrings) do
  12.     v:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
  13.     v:SetShadowOffset(0, 0)
  14.     v:SetTextColor(1,.92,0)
  15. end
  16.  
  17. local fontStrings = {
  18.     TargetFrameToTTextureFrameName,
  19.     FocusFrameToTTextureFrameName
  20. }
  21.  
  22. for _, v in pairs(fontStrings) do
  23.     v:SetTextColor(1,.92,0)
  24. end

As you can see, I want the top table to do the following but I only want the bottom part to set the text color. Is this the right way to do what I'm doing? It doesn't seem correct to make a new table.
  Reply With Quote
01-23-16, 09:58 PM   #2
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Lua Code:
  1. local fontStrings = {
  2.     PlayerName, -- 1
  3.  
  4.     TargetFrameTextureFrameName, -- 2
  5.     TargetFrameTextureFrameDeadText, -- 3
  6.  
  7.     FocusFrameTextureFrameName, -- 4
  8.     FocusFrameTextureFrameDeadText, -- 5
  9.  
  10.     TargetFrameToTTextureFrameName, -- 6
  11.     FocusFrameToTTextureFrameName, -- 7
  12. }
  13.  
  14. for k, v in pairs(fontStrings) do
  15.     if k < 6 then
  16.         v:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
  17.         v:SetShadowOffset(0, 0)
  18.     end
  19.     v:SetTextColor(1,.92,0)
  20. end

or...
Lua Code:
  1. local fontStrings = {
  2.     PlayerName,
  3.  
  4.     TargetFrameTextureFrameName,
  5.     TargetFrameTextureFrameDeadText,
  6.  
  7.     FocusFrameTextureFrameName,
  8.     FocusFrameTextureFrameDeadText
  9. }
  10.  
  11. for _, v in pairs(fontStrings) do
  12.     v:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
  13.     v:SetShadowOffset(0, 0)
  14. end
  15.  
  16. tinsert(fontStrings, TargetFrameToTTextureFrameName)
  17. tinsert(fontStrings, FocusFrameToTTextureFrameName)
  18.  
  19. for _, v in pairs(fontStrings) do
  20.     v:SetTextColor(1,.92,0)
  21. end
__________________
  Reply With Quote
01-23-16, 11:39 PM   #3
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
If you only have 2 cases you want treated separately, the shortest and simplest solution is to just call SetTextColor on those 2 font strings directly.
  Reply With Quote
01-24-16, 12:25 AM   #4
Lesteryoung
A Black Drake
Join Date: Aug 2015
Posts: 81
If you SetTextColor directly, are you supposed to make the fontstring local, like:

Code:
local FocusFrameToTTextureFrameName:SetTextColor(1,.92,0)
  Reply With Quote
01-24-16, 12:36 AM   #5
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Originally Posted by Lesteryoung View Post
If you SetTextColor directly, are you supposed to make the fontstring local, like:

Code:
local FocusFrameToTTextureFrameName:SetTextColor(1,.92,0)
There's no need to make local references to them, you can just use the name of the strings:
Lua Code:
  1. TargetFrameToTTextureFrameName:SetTextColor(1,.92,0)
  2. FocusFrameToTTextureFrameName:SetTextColor(1,.92,0)
  Reply With Quote
01-24-16, 02:36 AM   #6
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
Originally Posted by Lesteryoung View Post
If you SetTextColor directly, are you supposed to make the fontstring local, like:

Code:
local FocusFrameToTTextureFrameName:SetTextColor(1,.92,0)
Originally Posted by semlar View Post
There's no need to make local references to them, you can just use the name of the strings:
Lua Code:
  1. TargetFrameToTTextureFrameName:SetTextColor(1,.92,0)
  2. FocusFrameToTTextureFrameName:SetTextColor(1,.92,0)
That also isn't valid Lua syntax. You use local for variable declaration, not for expressions.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » How do I merge these two tables?

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