Thread: Tables again...
View Single Post
12-25-19, 11:02 PM   #10
Roeshambo
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Jul 2019
Posts: 5
Tables are basically arrays (but a bit more complex if you start manipulating meta tables etc). To break it down dummy style, you have indexed arrays (1, 2, 3, 4 as keys) and associative arrays (custom keys such as t["key1"]. ipairs will only cycle through the indexed keys (hence the I in it) and ignores the associative portion of the table. pairs covers all of it. It's really not confusing once you realize that if it's just a number, it's an indexed key. If it's got words, it's an associative key. But when you do ipairs, it will only cycle until it finds a nil value. So if you create keys 1, 2, 3 and 5, it will only cycle through 3 (since 4 is nil). Once you get that basic understanding down it gets really easy to see how they can be manipulated. Of course, they are NOT arrays. But you can very easily swap the concepts to get a basic understanding of them.

When you do table.insert(t, 1, 500), you're not replacing the 1 key's value. You're essentially pushing a new key value pair into the first position which pushes all other keys down one position. The point of an indexed table is they can be sorted and can be manipulated in that order (the keys don't remain constant). Where as in an associative array, if you sort it, you're going to have to use "next" or "for k,v" to cycle through it in the proper order.

Last edited by Roeshambo : 12-25-19 at 11:13 PM.
  Reply With Quote