What do you mean "returns nil"? Throws an error of nil reference? The code itself works fine. You can get a nil if you reference a key that doesn't exist in the table, but then if the "first bracket" reference resolved to nil, trying to resolve the second one will crash the game, it's the same as trying to do "nil[j]" and obviously it won't work.
You should allocate arrays in normal order, not reverse. GameMaker suffers performance-wise when you do it in normal order because it reallocates the array constantly, and in reverse it does it once. In LUA reallocation goes progressively less often as array grows so it's not of any concern. Plus, because of the way it works, you'll actually get better performance if you allocate it in normal order, one by one.
Just so you know, tables in LUA are hash-tables. It means they can have both integer keys and string keys. For what it's worth, any variable can pass for a key in LUA, even other tables. You can access literal keys with dot notation.
Code: Select all
foo[1] = "bar"
foo["bar"] = 10
foo.bar = 100 --last two are equivalent