

And the best part is, they're no more difficult to make than any other sort of table:


In lua they're essentially the same as any other table, except you can use just about anything you want as a key. Both ways are completely equivalent.Dictionaries are nice, but hash tables are where this really shines. You could also do this all in one line, lua also has an easy way of doing this tooįruittable2 = -Again the second value has no square brackets and quotations. You can add values in either of the following ways, they're both completely equivalentįruittable.banana = "yellow" -This version uses lua's 'syntactic sugar' which lets you use. Let's say you want put together a table of fruit and their colours Similarly, you can add all the table's items when making it, by putting them inside the original curly brackets: It is, however, shorter to type and allows for some very useful tables, which I'll get into later. This does pretty much the same thing as the previous method but it won't shift items. The more versatile method of adding items to a table is to use table = item. The table's values would now be: "def", "abc"The advantage of using table.insert can be seen when adding myitem2 to the table, it shifts any other items in the table over to make space for the newly added item instead of overwriting items or requiring you to shift everything yourself, the other method does not do this. Thus it is placed before myitem1 in the table and myitem 1 is shifted to position 2of the table Table.insert(mytable, 1, myitem2) -This adds myitem2 to position 1 of the table. Myitem2 = "def" -Make a new item to add to the table There is an optional argument to specify the position in the table you want to add it to.

Table.insert(mytable, myitem1) -This adds myitem1, namely the string "abc" to the end of the table. Myitem1 = "abc" -Make an item to add to the table
