Tables are one of the features of Lua script, that make the scripting language so dynamic & easy to use, as they allow us to easily create tables, insert, remove & sort data. Tables are often comprised of arrays that usually involve keywords - or an index number - & a value. Tables can be accessed using multiple different methods.
localt={1,2,3,4,5,"six",7,"ate",9}-- automatically assigns an index number to each value starting from 1localstr=""-- empty stringfori=1,#tdo-- for 1 to table total, print value of index numberstr=str..t[i]-- add current table index value to existing text data in the str variableifi<#tthenstr=str..", "end-- if i is less than table entry total then insert ", " into the str variableendprint("table data: "..str)-- print the table dataprint("table entry total: "..#(t))-- print total of table entries
method 2: manually created index values
localt={[1]=1,[2]="two",[3]=3,[4]=2*2,[5]="five",}localstr=""-- empty stringfori=1,#tdo-- for 1 to table total, print value of index numberstr=str..t[i]-- add current table index value to existing text data in the str variableifi<#tthenstr=str..", "end-- if i is less than table entry total then insert ", " into the str variableendprint("table data: "..str)-- print the table dataprint("table entry total: "..#(t))-- print total of table entries