Tables are probably the most powerful thing in Lua. You can store any type of object string, anything pretty much, even more tables! e.g:
local newtable = {}
or if you want to create a new table with stuff already inside it:
local newtable = {"string", 1, false, {"another table"}, workspace.Part}
Note this is just an array (or a list). To add something to an array use table.insert and to remove use table.remove. e.g:
local t = {"string", 1}
local x = Instance.new("Part")
x.Parent = workspace
table.insert(t, x)
table.insert(t, 1, x)
table.remove(t, 1)
To see how long our table is or see a specific part of the table we can do:
local t = {false, 1, 2, 3, "string"}
print(#t)
print(t[1], t[3])
To loop through tables there are two methods:
local t = {"string", false, true, 9, part}
for number, value in pairs(t) do
print(number, value)
end
or the other method:
local t = {"string", false, true, 9, part}
for i = 1,#t do
print(i, t[i])
end
Dictionaries
dictionaries are tables but allow you to name the values(pretty much):
local d = {
height = 50,
age = 19,
circles = 2
}
-to change a value :
d.age = 20
d.eyes = 2
EDIT:
local playertable = game.Players:GetChildren()
for i, plr in pairs(playertable) do
print (plr.Name)
end
1 comment
how!?