.. is a string concatenation operator
local txt = "abc" .. "def" -- txt is now "abcdef"
If your target is "Bob" then "blahblahblah "..UnitName("target") will append the strings to make "blahblahblah Bob"
Veeeering off topic (servers down), a really neat trick with lua is the "or" bit. Lua is fine using or/and on any variable type. In an "or", if the first expression is false, then it returns the second value.
local txt = UnitName("target") or "<no target>"
with Bob targeted: UnitName("target") is "BoB", so it takes that return.
with no target: UnitName("target") is nil, so it uses the second expression, "<no target>"
An "and" returns the second expression if the first expression is true.
So you can do things like:
local channel = (GetNumRaidMembers()>0 and "RAID") or (GetNumPartyMembers()>0 and "PARTY") or "SAY"
which is the equivalent of
Code:
channel = "SAY"
if GetNumRaidMembers()>0 then
channel = "RAID"
elseif GetNumPartyMembers()>0 then
channel = "PARTY"
end
If you're in a raid, GetNumRaidMembers()>0 is true so the first expression is "RAID".
If you're not in a raid, but in a party, the first expression is false, but the second is true, so it's "PARTY".
If you're neither in a raid or party, it will use the last expression "SAY".
It's great for initializing defaults too. I need to get in the habit of always assuming nil for default values, so this isn't the best way, but a few of my mods that have options added over time get default values assigned this way:
ItemRack_Settings.RightClick = ItemRack_Settings.RightClick or "OFF" -- 1.1
ItemRack_Settings.TinyTooltip = ItemRack_Settings.TinyTooltip or "OFF" -- 1.2
ItemRack_Settings.ShowTooltips = ItemRack_Settings.ShowTooltips or "ON" -- 1.2
ItemRack_Settings.RotateMenu = ItemRack_Settings.RotateMenu or "OFF" -- 1.3
ItemRack_Users[user].Spaces = ItemRack_Users[user].Spaces or {} -- 1.3
ItemRack_Users[user].Sets = ItemRack_Users[user].Sets or {} -- 1.4
So it uses the existing value if one exists, or sets a default if one doesn't exist. (the -- 1.x are the version numbers)
You'll need to be pretty careful on the order of operations too.
x = y and z or 1
is very different from
x = (y and z) or 1