So I’m doing some type checking in Lua. And I noticed that the type() function returns nil for booleans.
Now correct me if I’m wrong. But true and false are boolean values.
False is equal to nil. And anything that’s not false or nil, is true.
but type(false) returns “nil”.
It’s really weird. I’m quite literally using the false.
Here’s some of the code I’m using.
local DataType = {}
DataType["number"] = "NumberValue"
DataType["string"] = "StringValue"
DataType["boolean"] = "BoolValue"
DataType["nil"] = "BoolValue" -- Had to add this because type(false) returns nil.
And this is how the data looks, there’s a function with a for loop that creates containers for a given type that correlate to a given value instance as seen above.
local Container = Instance.new(DataType[type(v)])
Container.Name = k
Container.Value = v
If I was to send this table to this function for instance.
The Container.Value differs based on the type that’s returned. So it’s not always an integer, its more like it creates a container in which the value can be accepted. I’m iterating through this, and my implementation looks more like @sircfenner 's
sircfenner is correct though, I didn’t debug this correctly. My table which shouldn’t actually have any nil values, was and still is returning nil for some odd value that occasionally appears (Time for the hunt).
It is indeed returning as a boolean, It was an oversight on my part, I did not print k,type(v) as I should have. Instead I printed type(v) and assumed otherwise. So now it’s all about looking for that nil value.