Merely
|
  |
| Joined: 07 Dec 2010 |
| Total Posts: 17266 |
|
|
| 13 Aug 2011 12:44 PM |
What is the best way to do this? If at all possible, I would like to avoid...
if (pcall(function() print(x.className) end)) |
|
|
| Report Abuse |
|
|
Spectrumz
|
  |
| Joined: 22 Mar 2011 |
| Total Posts: 4338 |
|
|
| 13 Aug 2011 12:51 PM |
Hmmm. Maybe there's some kind of root to it, like BaseParts are the roots of all things solid. I would try doing:
if OBJ:IsA("Something goes here") then
But since I don't know what 'Something goes here' is, I can't really help you.
dere be an lmader in hour forum guyz trololololo |
|
|
| Report Abuse |
|
|
Merely
|
  |
| Joined: 07 Dec 2010 |
| Total Posts: 17266 |
|
|
| 13 Aug 2011 12:52 PM |
But that will error if OBJ is not an Instance...
But your'e right in that I don't want all Instances like functions, I want only parts |
|
|
| Report Abuse |
|
|
|
| 13 Aug 2011 12:54 PM |
if type(o) == "userdata" then end
Infortunately, userdata also includes the CFrame library and Vector3 libraries, as well as the math and string libraries. |
|
|
| Report Abuse |
|
|
|
| 13 Aug 2011 12:54 PM |
| There's a method called :IsA(), go to the wiki and search Structural Classes and in the brackets use the name of the class that fits what you want. |
|
|
| Report Abuse |
|
|
Spectrumz
|
  |
| Joined: 22 Mar 2011 |
| Total Posts: 4338 |
|
|
| 13 Aug 2011 12:56 PM |
http://wiki.roblox.com/index.php/PVInstance
Maybe that? |
|
|
| Report Abuse |
|
|
Merely
|
  |
| Joined: 07 Dec 2010 |
| Total Posts: 17266 |
|
|
| 13 Aug 2011 12:57 PM |
@AFF
Ik that, my code looks like
if type(i) ==-"userdata"
if i.className -- this line errors if it's not a thing |
|
|
| Report Abuse |
|
|
Merely
|
  |
| Joined: 07 Dec 2010 |
| Total Posts: 17266 |
|
|
| 13 Aug 2011 12:58 PM |
| Well IsA("PVInstance") will error if there is no IsA function in the instance... |
|
|
| Report Abuse |
|
|
Spectrumz
|
  |
| Joined: 22 Mar 2011 |
| Total Posts: 4338 |
|
|
| 13 Aug 2011 12:59 PM |
| PVInstance is all Parts or Models, but I don't think that's what you're looking for, is it? |
|
|
| Report Abuse |
|
|
Merely
|
  |
| Joined: 07 Dec 2010 |
| Total Posts: 17266 |
|
|
| 13 Aug 2011 01:00 PM |
Question
Is there any way to test if something is a PVInstance without using pcall! |
|
|
| Report Abuse |
|
|
Merely
|
  |
| Joined: 07 Dec 2010 |
| Total Posts: 17266 |
|
|
| 13 Aug 2011 01:01 PM |
| I mean is there any way to test if something has a className property kinda instance without using pcall. |
|
|
| Report Abuse |
|
|
Spectrumz
|
  |
| Joined: 22 Mar 2011 |
| Total Posts: 4338 |
|
|
| 13 Aug 2011 01:02 PM |
:IsA() works with BaseParts, so it should work with PVInstance. Try doing this:
function check(OBJ) if OBJ:IsA("PVInstance") then return true else return false end end
print(check(game.Workspace.Something)) |
|
|
| Report Abuse |
|
|
Merely
|
  |
| Joined: 07 Dec 2010 |
| Total Posts: 17266 |
|
|
| 13 Aug 2011 01:04 PM |
check(UDim.new()) -> IsA is not a valid member |
|
|
| Report Abuse |
|
|
Spectrumz
|
  |
| Joined: 22 Mar 2011 |
| Total Posts: 4338 |
|
|
| 13 Aug 2011 01:05 PM |
| But I don't think UDim2 is an Instance. It's a data type. |
|
|
| Report Abuse |
|
|
Merely
|
  |
| Joined: 07 Dec 2010 |
| Total Posts: 17266 |
|
|
| 13 Aug 2011 01:06 PM |
print(type(UDim.new()) -> userdata |
|
|
| Report Abuse |
|
|
Spectrumz
|
  |
| Joined: 22 Mar 2011 |
| Total Posts: 4338 |
|
|
| 13 Aug 2011 01:08 PM |
| I tried my function on a script in Workspace, and it returned false. I guess PVInstance won't work. |
|
|
| Report Abuse |
|
|
Merely
|
  |
| Joined: 07 Dec 2010 |
| Total Posts: 17266 |
|
|
| 13 Aug 2011 01:08 PM |
| How do I test if something has :IsA as opposed to a UDim or UDim2? |
|
|
| Report Abuse |
|
|
Merely
|
  |
| Joined: 07 Dec 2010 |
| Total Posts: 17266 |
|
|
| 13 Aug 2011 01:09 PM |
| ^ Without pcall if at all possible |
|
|
| Report Abuse |
|
|
|
| 13 Aug 2011 01:11 PM |
| Instead of using PVInstance try just Instance. |
|
|
| Report Abuse |
|
|
Spectrumz
|
  |
| Joined: 22 Mar 2011 |
| Total Posts: 4338 |
|
|
| 13 Aug 2011 01:12 PM |
Darn it, RATEX. I just found the answer on the Wiki.
http://wiki.roblox.com/index.php/IsA_%28Method%29
"print(game.Workspace:IsA("Instance"))" --> true" |
|
|
| Report Abuse |
|
|
|
| 13 Aug 2011 01:34 PM |
Let me make my own type function. :P
local type = function(val) local theType = type(val) if theType == "userdata" then if pcall(function() return val.Remove(Instance.new("Part")) end) then return "userdata" else return "library or value" end end end
print( type(math) ) print( type(workspace) )
> library or value userdata
Now each time you call type and get 'userdata' you're 100% sure it's an instance. |
|
|
| Report Abuse |
|
|
Merely
|
  |
| Joined: 07 Dec 2010 |
| Total Posts: 17266 |
|
|
| 13 Aug 2011 03:11 PM |
@Spec
But w/o pcall there's no good way correct? |
|
|
| Report Abuse |
|
|
Spectrumz
|
  |
| Joined: 22 Mar 2011 |
| Total Posts: 4338 |
|
|
| 13 Aug 2011 10:52 PM |
| Why would you need pcall()? That's what the if statement is for, to check if it's an Instance. |
|
|
| Report Abuse |
|
|