Maybe one of you lua gurus out there can help me out. I have the following code.
This code outputs:
I am wondering why the two array counting methods are not returning the correct count (should equal uCount, in this case 3). I read something somewhere that you can't have nil values in arrays in lua. I'm guessing this is the reason since uniqueblocks is indexed with integers, but some integers are not present. I don't know for sure.
Anyone know?
Code:
local uniqueblocks={}
local uCount = 0
for i = 1, #blocks do
idx = tonumber(blocks[i][1]) -- ANY INDEXED VALUE
if uniqueblocks[idx] == nil then
uniqueblocks[idx] = 0
uCount = uCount + 1
end
uniqueblocks[idx] = uniqueblocks[idx] + 1
end
print("number of block types: " .. uCount)
print("number of block types: " .. table.getn(uniqueblocks))
print("number of block types: " .. #uniqueblocks)
print(uniqueblocks[0])
print(uniqueblocks[35])
print(uniqueblocks[85])
This code outputs:
Code:
number of block types: 3
number of block types: 0
number of block types: 0
113
25
12
I am wondering why the two array counting methods are not returning the correct count (should equal uCount, in this case 3). I read something somewhere that you can't have nil values in arrays in lua. I'm guessing this is the reason since uniqueblocks is indexed with integers, but some integers are not present. I don't know for sure.
Anyone know?