Tables In Lua

Tables in Lua is called associative arrays. It is a flexible and powerful tool for storing and manipulating data. To create a table in Lua use following syntax:

First write the name of the table, then an equals sign = and curly braces {}. Within the brackets can be immediately set desired values, it may be numbers, text, in general, any type of data.

You can refer to an element by its index. By default, the first item is equal to 1. So to get the “Monday” from table d write d [1], as shown below.

If you want to refer to the element by name, you need to set the keys. You can do it in two ways.

You can refer to an element of a table as d.mon or d[“mon”].

One table can contain another table, as shown in the example below.

Then you can set or get the coordinates named player.position.x.