X_Z
(X_Z)
February 18, 2017, 5:49pm
#1
This just started happening today.
Basically when I do a print(#Table ) on a table that labels it’s values as dictionaries it just prints out 0
Example:
Script:
https://gyazo.com/d9657fbfaea8be7c396a66bd6cecc7e7
Output:
https://gyazo.com/96a632305c71e223c715a94605112a35
However if I just use normal table values without a dictionary, it works just fine:
Script:
https://gyazo.com/64acfdfa57fc5b0a9a768606ab485f6f
Output:
https://gyazo.com/5a2d0e2282523138939d99bf890dfbad
Is there a reason for this? It’s breaking my game’s datastores. I tried this in multiple of my places, but still no luck. Also there’s no difference when used on a local or regular script.
1 Like
ScriptOn
(Genya)
February 18, 2017, 5:52pm
#2
“#table ” works if there’s proper number indexes. You’re using strings as indexes.
It’s always been like this. # returns the highest continuous integer key.
local function GetNumElements(t)
local n = 0
for _ in next, t do n = n + 1 end
return n
end
Lua manual:
http://www.lua.org/manual/5.1/manual.html
2.5.5 – The Length Operator
The length operator is denoted by the unary operator #. The length of a string is its number of bytes (that is, the usual meaning of string length when each character is one byte).
The length of a table t is defined to be any integer index n such that t[n] is not nil and t[n+1] is nil; moreover, if t[1] is nil, n can be zero. For a regular array, with non-nil values from 1 to a given n, its length is exactly that n, the index of its last value. If the array has “holes” (that is, nil values between other non-nil values), then #t can be any of the indices that directly precedes a nil value (that is, it may consider any such nil value as the end of the array).
X_Z
(X_Z)
February 18, 2017, 7:33pm
#5
i just realized i was doing dumb mistake