How do tables work?

Hello! Im Jukes, a Beginner Scripter and Im very VERY confused on tables, please teach me tables in full depth or a good understanding that you know of it, the lua manual online is kinda hard to learn!

What specifically do you want to know about tables?

A table is a datatype. You use a table for storing multiple values in one place You can make a table by doing this
local myTable = {} or local myTable = table.create(10,"Nothing")

You can add stuff into a table by using []
like this
myTable[3] -- Number refers to what position or index it is in the table

There are two types
Arrays
Dictionaries

Arrays are the ones where you put a number into the bracket to get a value[]

local array= {"Yes","No"}
print(array[2]) -- prints No

Dictionaries are the ones where you put another value in to the bracket to access the data ["Bob"]

local dictionary = {
    Gob = "INter",
    biset = "OwrE"
}
print(dictionary["Gob"])

Here are both a dictionary and a table

This are the basics of what tables are for more info view the article or ask a more specialized question.

2 Likes

The easiest way I think about tables, is basically a list.

local list = {"This", "Is","A", "List", "Of", "Words"}

There you got a list, its a pair of {} with commas inside to seperate the items in the list.

If you want to reference something in the list:

local referenceOfList = list[1]

Every item in the list has a number based on its order, “This” is 1, " Is" is 2nd, “A” is third in the list. So if you did list[1] you are referencing the first thing in the list, which is “This”

So referenceOfList would equal “This”

Hope that helps!

1 Like

The best way to use it is like a list:

local tablee = {5,"Value",true,nil}

Using {} is calling an array/dictionary and use commas to separate the values inside the table.
Call something in the list like this:

print(tablee[1]) --// Prints 5
--etc.

You add [1] to reference the first value in the array/dictionary
you can also do [2] [3] etc. if you have a table in a table you can do this

local myTable = {
    ["TableAgain"] = {
        5,
    }
}

print(myTable[1][1]) --// I am sure this works will test later
2 Likes