Can I use a float (decimal number) to index a table, so tbl[2] is different from tbl[2.5]?
Turns out you can’t.
Works fine:
function setup()
x={}
x[2] = "hi"
x[2.5] = "there"
print(x[2])
print(x[2.5])
end
This prints:
hi
there
in the output area.
The only object you can’t use as a table key is “nil”.
Let me add, you cannot use x[2] and x[2.0] however, because internally 2 = 2.0 because Lua’s numbers are only floating point (there’s no separate integer type). Which in turn implies that all numeric table keys are floats.
I understand that, I didn’t use print or anything to test it but it failed to work in a for loop even with index[i-0.5] I changed it to a whole number anyway