local MyTable = {"Foo", "Fee"} print(MyTable[1], MyTable[2])
I can do that fine, but what if the script doesn't know how many there are in the table? How do I make it so it prints the entire table onto one line rather than:
Foo Fee
I would have
Foo Fee
I'm guessing it would require some sort of loops so all I've come up with is this:
for x, Table in pairs(MyTable) do print(Table) --But how do I keep them all on one line? end
table.concat!
print(table.concat(myTable," this is inbetween the things"))
for more information, check the wiki page for table.concat
The CompileTable is the solution! It will print as {"Foo","Fee"}
function compileTable(table) local index = 1 local holder = "{" while true do if type(table[index]) == "function" then index = index + 1 elseif type(table[index]) == "table" then holder = holder..compileTable(table[index]) elseif type(table[index]) == "number" then holder = holder..tostring(table[index]) elseif type(table[index]) == "string" then holder = holder.."\""..table[index].."\"" elseif table[index] == nil then holder = holder.."nil" elseif type(table[index]) == "boolean" then holder = (table[index] and "true" or "false") end if index + 1 > #table then break end holder = holder.."," index = index + 1 end return holder.."}" end local compiledTable = compileTable(MyTable) print(compiledTable)