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

does local table = {} mean empty?

while learning how to code, I have kept seeing some people use a table without anyone inside like this:

local table = {}

i keep on wondering and thinking if that means it’s empty or there are something in it. Also i wonder on what those are used for. Any help would be great, thanks!

1 comment

0

yep

1 answer

✓ Accepted answer

Yes, this is an empty table. But you should not name a table "table", because that is a special keyword on roblox. Any text that turns blue is a special keyword you should not use to name anything in your code. Tables are basically arrays or a list. They can store information like strings, booleans, functions, and more. Usually people use them to store items in a player's inventory.

local myTable = {} -- Empty
table.insert(myTable, "Oranges") -- Inserting the string "Oranges"
print (myTable[1]) -- Printing the first item in our table: Oranges
-- Inserting Apples, Grapes, and Bananas
table.insert(myTable, "Apples")
table.insert(myTable, "Grapes")
table.insert(myTable, "Bananas")
table.remove(myTable, 3) -- removing the 3rd item in our array/table/list: Bananas

for i, v in pairs(myTable)do -- printing every item in our list
	print (i, v)
end

4 comments

0

Output of this code will be: Oranges 1 Oranges 2 Apples 3 Bananas

0

what are empty tables used for anyways?

0

they are used for if you need to insert other stuff into the table later, or clear a table for other reasons.

0

ahhh. Thanks again!

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