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: :IsA or .ClassName?

Previous Thread :: Next Thread 
tuxedoman23 is not online. tuxedoman23
Joined: 24 Apr 2009
Total Posts: 4670
02 Jan 2014 04:09 AM
Which is more effective in conditional statements and why?
Report Abuse
lampwnage121 is not online. lampwnage121
Joined: 20 Oct 2012
Total Posts: 4285
02 Jan 2014 04:13 AM
:IsA, It`s shorter and you have the additional option to include all base objects
Report Abuse
NXTBoy is not online. NXTBoy
Joined: 25 Aug 2008
Total Posts: 4533
02 Jan 2014 04:21 AM
    Instance.new("Part"):IsA("BasePart") == true
    Instance.new("TrussPart"):IsA("BasePart") == true

vs

    (Instance.new("Part").ClassName == "Part") == true
    (Instance.new("TrussPart").ClassName == "Part") == false
Report Abuse
tuxedoman23 is not online. tuxedoman23
Joined: 24 Apr 2009
Total Posts: 4670
02 Jan 2014 04:27 AM
Oh, I see.
Report Abuse
TheRobloxian909 is not online. TheRobloxian909
Joined: 08 Aug 2013
Total Posts: 2444
02 Jan 2014 05:39 AM
:IsA("") is better.
Report Abuse
Radioaktiivinen is not online. Radioaktiivinen
Joined: 25 Apr 2009
Total Posts: 18629
02 Jan 2014 10:08 AM
Basically IsA is aware of the whole 'inheritance' hierarchy that forms an object, while classname only knows the concrete type of the object.
Report Abuse
littleAU999 is not online. littleAU999
Joined: 15 Jan 2011
Total Posts: 1375
02 Jan 2014 12:30 PM
radio +1

Part = Instance.new"Part"
print(Part:isA"Part") >> true
print(Part:isA"BasePart") >> true
print(Part:isA"Instance") >> true
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
02 Jan 2014 02:21 PM
If you are only checking for the class, I'm pretty sure class name would be.
Report Abuse
Seranok is not online. Seranok
Joined: 12 Dec 2009
Total Posts: 11083
02 Jan 2014 02:26 PM
If you are doing something like checking if an instance is a player, I recommend instance:IsA("Player"). Only use instance.ClassName == "Player" if you only want to match that specific class.
Report Abuse
Radioaktiivinen is not online. Radioaktiivinen
Joined: 25 Apr 2009
Total Posts: 18629
02 Jan 2014 02:50 PM
I wouldnt use .ClassName in that case either (.className=="Player"), because in theory roblox could always replace an object with multiple subobjects (as in NPCPlayer and RealPlayer)

but because they are subobjects, you should be safe to assume they can be treated as the higher level object (Player)

Thus for forwards compatibility you should always use :IsA, no exceptions.
Report Abuse
RaidenJPN is not online. RaidenJPN
Joined: 22 May 2013
Total Posts: 6920
02 Jan 2014 02:58 PM
I've always used :IsA,

it's more effective,

and I don't like how .ClassName looks.
Report Abuse
coolblox2334 is not online. coolblox2334
Joined: 10 Dec 2010
Total Posts: 4605
02 Jan 2014 03:07 PM
guys
go to scripting helpers
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
02 Jan 2014 03:19 PM
But in speed, would class name be faster since you aren't calling a method?
Report Abuse
RaidenJPN is not online. RaidenJPN
Joined: 22 May 2013
Total Posts: 6920
02 Jan 2014 03:32 PM
@cnt,

Yes,

but only by a minuscule amount of time.
Report Abuse
NVI is not online. NVI
Joined: 11 Jan 2009
Total Posts: 4744
02 Jan 2014 05:59 PM
Actually, no, it's not faster because you're still calling across the Lua-C boundary which is essentially the same weight for functions or indexing methods. Plus, you have a comparison operator on it too. So it's infinitesimally faster to call :IsA(). But seriously, this is an "optimization" that makes no sense and won't ever be a problem.
Report Abuse
misgav11 is not online. misgav11
Joined: 21 Apr 2011
Total Posts: 3418
02 Jan 2014 06:01 PM
i usually us :IsA because is faster and cleaner but in some cases i use .ClassName, but yet again im not sure if i can do this:

if not v:IsA("Part") then.

so use :IsA
Report Abuse
NVI is not online. NVI
Joined: 11 Jan 2009
Total Posts: 4744
02 Jan 2014 06:04 PM
Well, IsA returns true or false... so of course you can do that. But you're better off using it more like this:

if p:IsA("BasePart") then

Because then you can catch everything that's a physical part - that's what its intended use is, checking if something inherits from a certain class. That expression above would work for Part, Seat, VehicleSeat, PlatformSeat(whatever it's called?), WedgePart, etc.
Report Abuse
misgav11 is not online. misgav11
Joined: 21 Apr 2011
Total Posts: 3418
02 Jan 2014 06:09 PM
^^
i know, but sometimes i use part for just parts, or just being specific.
Report Abuse
TutorialBlox is not online. TutorialBlox
Joined: 01 Apr 2010
Total Posts: 1586
02 Jan 2014 10:04 PM
What is the actual difference between the two?
Report Abuse
MettaurSp is not online. MettaurSp
Joined: 20 Mar 2010
Total Posts: 3179
02 Jan 2014 10:07 PM
Tutorial, did you even read the thread?
Report Abuse
mew903 is not online. mew903
Joined: 03 Aug 2008
Total Posts: 22071
02 Jan 2014 10:49 PM
There seems to be no performance differences between the two, so it all really depends on how much you want to type at the time.
Report Abuse
MettaurSp is not online. MettaurSp
Joined: 20 Mar 2010
Total Posts: 3179
02 Jan 2014 10:54 PM
And as misgav stated whether you want to include derived classes or be specific about the class.
Report Abuse
TutorialBlox is not online. TutorialBlox
Joined: 01 Apr 2010
Total Posts: 1586
03 Jan 2014 09:05 PM
I don't get it.
Report Abuse
lampwnage121 is not online. lampwnage121
Joined: 20 Oct 2012
Total Posts: 4285
04 Jan 2014 12:52 AM
uwot
Report Abuse
Tenal is not online. Tenal
Joined: 15 May 2011
Total Posts: 18684
04 Jan 2014 10:31 AM
This gets really helpful sometimes.
You can put "GuiObject" as the argument and even though there isn't an instance called that, it still returns true for all GUI objects.
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