|
| 02 Jan 2014 04:09 AM |
| Which is more effective in conditional statements and why? |
|
|
| Report Abuse |
|
|
|
| 02 Jan 2014 04:13 AM |
| :IsA, It`s shorter and you have the additional option to include all base objects |
|
|
| Report Abuse |
|
|
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 |
|
|
| |
|
| |
|
|
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 02 Jan 2014 03:07 PM |
guys go to scripting helpers |
|
|
| Report Abuse |
|
|
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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 02 Jan 2014 10:04 PM |
| What is the actual difference between the two? |
|
|
| Report Abuse |
|
|
MettaurSp
|
  |
| Joined: 20 Mar 2010 |
| Total Posts: 3179 |
|
|
| 02 Jan 2014 10:07 PM |
| Tutorial, did you even read the thread? |
|
|
| Report Abuse |
|
|
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
|
  |
| 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 |
|
|
| |
|
| |
|
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 |
|
|