Reputation: 11
I want to insert key,value pairs into a table
my_table = {}
for i=1, GetNumGroupMembers() do
local unitID = "group"..i
my_table.unitID = UnitName(unitID)
end
for key,value in pairs(my_table) do print(key,value) end
RESULT:
unitID group1
why is the key always "unitID"
? I need the VALUE of unitID
as key, not the variable name
Upvotes: 1
Views: 443
Reputation: 10776
The key is always unitID
because that's what you call it literally when doing
my_table.unitID = UnitName(unitID)
what you want to do is
my_table[unitID] = UnitName(unitID)
Which will use the value of the variable unitID as the key.
Upvotes: 5