lua table
snippet in lua

table lua


    a = {}
    x = "y"
    a[x] = 10                 -- put 10 in field "y"
    print(a[x])   --> 10      -- value of field "y"
    print(a.x)    --> nil     -- value of field "x" (undefined)
    print(a.y)    --> 10      -- value of field "y"

lua table


local t = {

for k,v in pairs(t) do
	print("Number: "..k.."Message: "..t)

Number: 1 Message: hello
Number: 2 Message: how
Number: 3 Message: are
Number: 4 Message: you

table in lua


local myTable = {}

lua print all elements table


local people = {
       name = "Fred",
       address = "16 Long Street",
       phone = "123456"
       name = "Wilma",
       address = "16 Long Street",
       phone = "123456"
       name = "Barney",
       address = "17 Long Street",
       phone = "123457"

for index, data in ipairs(people) do

    for key, value in pairs(data) do
        print('\t', key, value)

lua table


local Table = {
	Part ="Part")
-- This is our table!

This will print the amount of stuff inside the table by numbers!
For example, if you had 140 objects inside a table (doesn't matter if it's a
string) then print(#Table) will print out the number 140, exactly how many
things are inside the table!

Output: (the amount of objects inside the table BY NUMBERS)


for i, v in pairs(Table) do
This is a for loop. It will go through each and every object inside the table.

i is the index. The index is like the line number, where the object is located.
Let's say that Bob is the 4th object in the table.
If we would think of tables as lines, Bob would be at line 4.
So if we'll do print(i) it would print out the line where Bob is.
Output: 4
As long as you use a for loop to get every object!

v is the object itself.
Let's say yet again that Mark is inside the table.
so v would be counted as Mark himself.
if we would do print(v) it will print out the name,string etc. of the object!

Output: Mark

lua empty table


for k,v in pairs(table) do 
 table.remove(table, k)