Why does this print 0? I really don't understand why.
local kRef = {
["w"] = Enum.KeyCode.W,
["a"] = Enum.KeyCode.A,
["s"] = Enum.KeyCode.S,
["d"] = Enum.KeyCode.D,
["space"] = Enum.KeyCode.Space
}
print(#kRef)
Why does this print 0? I really don't understand why.
local kRef = {
["w"] = Enum.KeyCode.W,
["a"] = Enum.KeyCode.A,
["s"] = Enum.KeyCode.S,
["d"] = Enum.KeyCode.D,
["space"] = Enum.KeyCode.Space
}
print(#kRef)
###When a dictionary is created, the keys inside of it do not have an order. Because of that, iterating through a dictionary may not give the values in the order you wrote. This is also why #keyRef printed 0, because of how the keys are stored. In order to fix this, you should remove the dictionary's indexes and make it a normal table.
local kRef = {
Enum.KeyCode.W,
Enum.KeyCode.A,
Enum.KeyCode.S,
Enum.KeyCode.D,
Enum.KeyCode.Space
}
print(#kRef) --> 5
local kRef = {
["w"] = Enum.KeyCode.W,
["a"] = Enum.KeyCode.A,
["s"] = Enum.KeyCode.S,
["d"] = Enum.KeyCode.D,
["space"] = Enum.KeyCode.Space
}
--If you want to print all the table's contents, use a loop:
for i, v in pairs(kRef) do
print(v)
end
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
I don't want the content, I want the size, and the size is 0.