Is there a way to get the class/type name of things like BrickColors, Vector3s, etc.
Reason: I usually put assertions in my functions to check that an arguments that it is called with are valid. For Instances, I can check the ClassName property of it, or use the IsA method, but for other things, I cannot.
Example:
function SetColor (Part, Color) assert(type(Part) == "userdata" and part:IsA("BasePart), "bad argument #1 to \'SetColor\' (BasePart expected) ") -- This would work assert(type(Color) == "userdata" and Color:IsA("BrickColor"), "bad argument #2 to \'SetColor\' (expected BrickColor)") -- Does not work as BrickColor does not have the IsA Method assert(type(Color) == "userdata" and Color.ClassName == "BrickColor", "bad argument #2 to \'SetColor\' (expected BrickColor)") -- Does not work as BrickColor does not have the property ClassName part.BrickColor = BrickColor end
This is just an example, and not a real use case.
I know I could use something like
function SetColor (part, Color) -- assert part is part local a, b = pcall(function() part.BrickColor = Color end) if not a then error("bad argument #2 to \'SetColor\' (" .. b:match("([^%(]*)%)$") .. ")") end end
But it does not seem that efficient.
I just remembered the method for doing this, `typeof``. This function returns the type of object provided.
print(typeof(Vector3.new())
Vector3
Locked by Link150
This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.
Why was this question closed?