generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Determining a variable's class?

Previous Thread :: Next Thread 
Spirographic is not online. Spirographic
Joined: 17 Aug 2007
Total Posts: 19084
03 Mar 2015 05:12 PM
What I'm looking at doing is finding a way to determine the class of a variable and return whether it's a string, vector3, cframe, udim2, etc.

Is there any easy way to do this?
Report Abuse
protectiveEBob is not online. protectiveEBob
Joined: 09 Jul 2012
Total Posts: 1297
03 Mar 2015 05:34 PM
Yep.
print(type(variable))
Report Abuse
nighttimeninja314 is not online. nighttimeninja314
Joined: 04 Apr 2011
Total Posts: 4001
03 Mar 2015 05:36 PM
However, many of those are considered userdata values.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
03 Mar 2015 05:36 PM
Nope, type only gets the datatype, the class itself is not so easy.

local isVector3 = function(userdata)
assert(type(userdata) == "userdata", "userdata expected, got " .. type(userdata));
return pcall(function() return userdata.isClose; end);
end;
Report Abuse
nighttimeninja314 is not online. nighttimeninja314
Joined: 04 Apr 2011
Total Posts: 4001
03 Mar 2015 05:36 PM
However, many of those are considered userdata values
Report Abuse
nighttimeninja314 is not online. nighttimeninja314
Joined: 04 Apr 2011
Total Posts: 4001
03 Mar 2015 05:37 PM
agh floodcheck-double-post-glitch
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
03 Mar 2015 05:42 PM
If you were using MoonScript, it looks WAY cleaner and prettier than Lua. This is a function I wrote (Modified by eLunate) that I converted to MoonScript.

GetType = (Value) ->
Type = type Value
return Type if Type != "userdata"
return "Instance" if pcall -> return Value.IsA
return "CFrame" if pcall -> return Value.p
return "Vector3" if pcall -> return Value.Z
return "UDim2" if pcall -> return Value.X.Offset
return "Vector2" if pcall -> return Value.X
return "BrickColor" if pcall -> return Value.Color
return "Color3" if pcall -> return Value.r
return "Ray" if pcall -> return Value.ClosestPoint
return "Region3int16" if pcall -> return Value.Min
return "Region3" if pcall -> return Value.CFrame
return "UDim" if pcall -> return Value.Scale
return "Event" if pcall -> return Value.connect
return "Connection" if pcall -> return Value.disconnect
return "Unknown"

Unfortunately, I can't see any way it will ever look pretty in Lua.
Report Abuse
HexC3D is not online. HexC3D
Joined: 30 Jun 2012
Total Posts: 10044
03 Mar 2015 05:44 PM
SPIRO!!
NICE TO see YOU!
Report Abuse
Spirographic is not online. Spirographic
Joined: 17 Aug 2007
Total Posts: 19084
03 Mar 2015 05:45 PM
@hex
Hmm? I'm not sure we've met, but it's been a while since I've been here.

And thanks @cnt. I suppose something like that will be my best bet, ahah.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image