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 » Scripting Helpers
Home Search
 

Re: Best way to test if something is an instance?

Previous Thread :: Next Thread 
Merely is not online. 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 is not online. 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 is not online. 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
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
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
RATEXmegaGAMER is not online. RATEXmegaGAMER
Joined: 10 Dec 2010
Total Posts: 4046
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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. Merely
Joined: 07 Dec 2010
Total Posts: 17266
13 Aug 2011 01:06 PM
print(type(UDim.new())
-> userdata
Report Abuse
Spectrumz is not online. 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 is not online. 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 is not online. Merely
Joined: 07 Dec 2010
Total Posts: 17266
13 Aug 2011 01:09 PM
^ Without pcall if at all possible
Report Abuse
RATEXmegaGAMER is not online. RATEXmegaGAMER
Joined: 10 Dec 2010
Total Posts: 4046
13 Aug 2011 01:11 PM
Instead of using PVInstance try just Instance.
Report Abuse
Spectrumz is not online. 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
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
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 is not online. 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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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