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

how to keys/indexes work in tables?

Asked by 4 years ago

Hi, if i were to set a key for a table which position would that key be placed in?. would be placed in the first position, last or a random one?. for example.

local myTable = {}
myTable[myKey] = " this is a key"

and can i set a key without giving it a value such as

local myTable = {}
myTable[myKey] 
0
local myTable = { ["Key"] = "Table key"; } . Ziffixture 6913 — 4y
0
could you answer my questions? Code1400 75 — 4y
0
You may want to accept my answer. :)) LinavolicaDev 570 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

Yes, it can, but you have to set it to "nil". Take this, as an example:

local table = {}
table["Key01"] = nil;
--^ The Key01 is the key, the value is stored in a "pair" of the Key01 and nil.
0
thak you, and does it insert that key into the first available slot?. for example if my table had keys going from 1, 5 would it insert in the 6th position Code1400 75 — 4y
0
This is not a table, this would be an array. LinavolicaDev 570 — 4y
0
And yes, you can insert it like this. LinavolicaDev 570 — 4y
0
thanks Code1400 75 — 4y
Ad

Answer this question