I am attempting to make a WoW addon and am saving some guild data in a 2D array. I have successfully saved the data to the array but am having trouble getting it back out.
local playerName = UnitName("player");
ChatFrame1:AddMessage('Hi my name is: ' .. playerName);
local guildMembers = {}
local totalMembers, onlineMembers = GetNumGuildMembers();
local visibleMembers = onlineMembers;
local guildMembers = {}
if ( GetGuildRosterShowOffline() ) then
visibleMembers = totalMembers;
end
for index=1, visibleMembers do
local name = GetGuildRosterInfo(index);
local weeklyXP = GetGuildRosterContribution(index);
guildMembers[index] = {}
guildMembers[index][1] = name;
guildMembers[index][2] = weeklyXP;
--DEFAULT_CHAT_FRAME:AddMessage('name: '..guildMembers[index][1]..' weeklyXP: '..guildMembers[index][2]);
end
for i, v in pairs(guildMembers) do
for j, v2 in pairs(i) do
print(i.. ': ' ..v.. ' xp: ' ..v2);
end
end
Everything seems to work but for the last nested for loop. Just a note, my array may skip numbers. I have Google it but most of the questions asked knew how long their array was and I do not. Thanks for the help!
Try using a numerical for loop instead of a generic one.
Or you could use a dictionary: