Originally Posted by Roupine
You could wrap it in {} to get a table and index it from there:
Lua Code:
local buffInfo = {GetUnitBuffInfo("player",1)}
|
I could, but that would still leave nine unnecessary table entries.
The correct way (which I just learned and want to share) of getting the last value from GetUnitBuffInfo() is using select():
Lua Code:
local lastValue = select(10, GetUnitBuffInfo("player", 1))
http://www.lua.org/manual/5.1/manual.html:
select (index, ···)
If index is a number, returns all arguments after argument number index. Otherwise, index must be the string "#", and select returns the total number of extra arguments it received.
|
Here's an example showing the difference:
Lua Code:
function manyReturns()
return "alfa", "beta", "gamma"
end
t = {manyReturns()}
for k,v in pairs(t) do
print(k..": "..v)
end
v = select("#", manyReturns())
print(v)
r = select(v, manyReturns())
print(r)
Which outputs:
Code:
1: alfa
2: beta
3: gamma
3
gamma
Not so messy after all