Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

How do you print everything in a table in the same line? [Answered]

Asked by 8 years ago

I was wondering if anyone can tell me how to print anything in a table(temptable) in the same line, without creating a new one for each item in it.

Script I've tried:

local temptable = {"Test","Test2"}
for _,v in pairs(temptable) do
    print(v)
end

But that does:

Test
Test2

Instead, I want it to do:

Test Test2

Any suggestions on how I could accomplish this? Any help appreciated.

1
http://wiki.roblox.com/index.php?title=Function_dump/Basic_functions#unpack doot. You may also want to look at table.concat: http://wiki.roblox.com/index.php?title=Function_dump/Table_manipulation#table.concat XAXA 1569 — 8y
1
Thanks, table.concat worked. ISellCows 2 — 8y
0
Does the write() work in roblox? You could try it. I know it's answered... Just saying. User#11440 120 — 8y

1 answer

Log in to vote
5
Answered by 8 years ago

A nice, built-in Lua function for working with tables: unpack (or table.unpack in Lua 5.3)

table = {'as', 'df'};

print(unpack(table));
0
This is awesome. Thank you for the great answer! I couldn't find this anywhere on the internet except here. joeldes 201 — 6y
Ad

Answer this question