Here is a code:
users = {}
users["aaa"] = "bbbb";
users["bbb"] = "bbbb";
users["ccc"] = "bbbb";
print("Users count ", table.getn(users));
Why table.getn(users) always returns 0? BTW, #users returns 0 too. So, am I doing something wrong and there is another way to get the amount of elements in the array?
The setn function is used to set the size of the array explicitly and the getn is used to extract the size that was set by the setn.
In Lua, arrays are implemented using indexing tables with integers. The size of an array is not fixed and it can grow based on our requirements, subject to memory constraints.
Because 64 Bit per number * 2^25 = 2147483648 Bits which are exactly 2 GB.
table.maxn and # look for numeric indices; they won't see your string indices.
As for getting the number of elements in an array with arbitrary indices, I'd probably walk the array using something like:
Count = 0
for Index, Value in pairs( Victim ) do
Count = Count + 1
end
but I'm an idiot.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With