Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to find class of non-instance values? [closed]

Asked by 7 years ago
Edited 7 years ago

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.

0
Nevermind: just remembered that Roblox has a function called typeof which does this. EpidemioIogy 4 — 7y

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?

1 answer

Log in to vote
1
Answered by 7 years ago

I just remembered the method for doing this, `typeof``. This function returns the type of object provided.

print(typeof(Vector3.new())

Vector3

Ad