Arrays

An array is an ordered collection of values.

In Lunaris, arrays are built on top of tables, but they are used specifically for list-like data.

local items = ["Sword", "Shield", "Potion"]

print(items[0]) // Sword
print(items[1]) // Shield
print(items[2]) // Potion

Use arrays when:

  • order matters
  • you want to iterate over a list
  • you want to store many values of the same kind

You can loop over an array with for.

local items = ["Sword", "Shield", "Potion"]

for (item in items) {
    print(item)
}

If you need named fields instead of ordered entries, use a Table instead.

Categories:

Updated: