• How to use table.add and have a subtable?
    4 replies, posted
I'm having trouble getting my head around this one as everything I tried seems to be no where close. There's no good resources on this either for making sub tables For example I want a table when printed looks like: Where - is a sub part of the first table 1:Playername -playerjob -playermodel 2:Playername -playerjob -playermodel I thought I could do generalList = {}  tempList = {playername,{playerjob,playermodel,}} -- 2 with different values  tempList = {playername,{playerjob,playermodel,}} -- 2 with different values table.Add(generalList, tempList)
Not tested but i think you can do generalist = { {playername,{playerjob,playermodel}, {playername,{playerjob,playermodel} }
What if i'm trying to add them via a loop?
Untested but table.Add( generalList, {playername, {playerjob,playermodel} } ) should work fine
generalList = {} for i=1, 100 do local tempList = {playername,{playerjob,playermodel,}} generalList[i] = tempList --or table.insert(generalList, tempList) end Note that table.Add adds the CONTENTS of a table to another. This means you'd end up with a table which looks like this:gene generalList = {playername,{playerjob,playermodel,}, playername2,{playerjob2,playermodel2,}, playername3,{playerjob3,playermodel3,}} One more thing. Unless the order of your table is important, I recommend structuring it like this instead of what I said at the beginning of this post: generalList = {} for k,v in pairs(player.GetAll()) do local playername, playerjob, playermodel = v:Nick(), v:Team(), v:GetModel() generalList[playername] = {playerjob,playermodel} end --then, to get values from the table: for k,v in pairs(generalList)do print("Name: "..k, "Job: "..team.GetName(v[1]), "Model: "..v[2]) end
Sorry, you need to Log In to post a reply to this thread.