FANDOM


A table is similar to a list—a group of related numbers, strings, objects, or even other tables. Tables can be very useful when doing intermediate or advanced scripting.

Creating a table

Curly brackets are used to create tables:

local t = {"apple", "banana", "peach", "papaya", "pear"}

Getting data from a table

To get data from a table, use square brackets.

fruit = t[1]
 print(fruit) --prints "apple"
 anotherfruit = t[4]
 print(anotherfruit) --prints "papaya"

Dictionaries

You can also use tables as simple key/value pairs. The creation is similar to a normal table (array).

local t = {apple="green", orange="orange", banana="yellow"}

Getting information is similar; you use the key name instead of a number index.

color = t[banana]
 print(color) -- prints "yellow"

See also

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.