Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Could someone explain to me what unpack() does and what it is used for?

I've seen it here and there but never understood what it is used for, could someone explain what unpack() is for?

2 answers

✓ Accepted answer

What is unpack used for?

Unpack is used for separating values in a table for example

local Table = {"g","o","o","d","a","d","m","i","n","s"} -- This is my Table

print(unpack(Table)) -- This unpacks the table and prints it as separate values

Output

g o o d a d m i n s

This prints all the content of the table in one line

3 comments

0

They're called elements not "content"

0

Actually the things inside the table are the tables 'content' smart kid

0

I can’t tell if you’re serious or not, first you downvote a correct answer then you refer to elements as “things”

local t = {"1","2","3","4","5"}
print(unpack(t))

Above code prints out each element in 't', starting from index 1. A brief explanation would be as follows:

unpack is a special function in Lua which receives a specified table and returns the elements in that table in consecutive order, starting from index 1.

This discussion is preserved as it was. New answers, comments, and votes are closed.