Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What is the difference between these syntaxes?

Asked by 4 years ago
local tbl = {}
local tbl2 = {}

tbl[tbl2] = {position = 12}
tbl.tb2.position = 12

--Difference between those 2 on line 4 and 5?
0
Both of these are wrong. The first one tries to use a table as a key, which you can't do. The second one tries to index "position" of a nil value. ThatPreston 354 — 4y
0
Tb2 doesn’t exist, not would correcting it to tbl2. It would need to be created vis table.insert() or initiated in tbl’s creation. This counts for position too. Ziffixture 6913 — 4y
0
Although you can use an array as an index, it is v e r y not recommended. Ziffixture 6913 — 4y
0
I don't really have a good understanding of how lua indexes work. So like if I had a foo variable with a value of 4 inside of a table, is the foo an index for the value of 4? Physosear 10 — 4y

Answer this question