Code: Select all
If ((other.isa('something'))
{
...
}
Code: Select all
if (something(other) != none)
{
}
Code: Select all
If ((other.isa('something'))
{
...
}
Code: Select all
if (something(other) != none)
{
}
Code: Select all
function something()
{
local pawn p;
if ( owner != none && owner.IsA('Pawn') ) // check if it's a pawn, since owner can be any actor
{
p = pawn(owner);
p.health = 100;
p.groundspeed = 500;
...
}
}
Code: Select all
other.isa('something')
Code: Select all
something(other)
Code: Select all
SomeActor.IsA('WhatEverClass')
Code: Select all
String(SomeActor.Class.name) ~= "WhatEverClass"
Code: Select all
SomeActor(OtherActor) != None
ClassIsChildOf(class TestClass, class ParentClass)
Code: Select all
if (....Owner.Isa('Pawn'))
Code: Select all
if (....Owner.bIsPawn) //Prevent Non-Pawns from being checked and it takes almost nothing in CPU timer
{
//Do the rest of checks
}
Code: Select all
//
// See if this object belongs to the specified class.
//
inline UBOOL UObject::IsA( class UClass* SomeBase ) const
{
guardSlow(UObject::IsA);
for( UClass* TempClass=Class; TempClass; TempClass=(UClass*)TempClass->SuperField )
if( TempClass==SomeBase )
return 1;
return SomeBase==NULL;
unguardobjSlow;
}
https://www.joelonsoftware.com/2005/05/ ... ook-wrong/In general, I have to admit that I’m a little bit scared of language features that hide things. When you see the code
… in C you know, at least, that j is being multiplied by five and the results stored in i.Code: Select all
i = j * 5;
But if you see that same snippet of code in C++, you don’t know anything. Nothing. The only way to know what’s really happening in C++ is to find out what types i and j are, something which might be declared somewhere altogether else. That’s because j might be of a type that has operator* overloaded and it does something terribly witty when you try to multiply it. And i might be of a type that has operator= overloaded, and the types might not be compatible so an automatic type coercion function might end up being called. And the only way to find out is not only to check the type of the variables, but to find the code that implements that type, and God help you if there’s inheritance somewhere, because now you have to traipse all the way up the class hierarchy all by yourself trying to find where that code really is, and if there’s polymorphism somewhere, you’re really in trouble because it’s not enough to know what type i and j are declared, you have to know what type they are right now, which might involve inspecting an arbitrary amount of code and you can never really be sure if you’ve looked everywhere thanks to the halting problem (phew!).
When you see i=j*5 in C++ you are really on your own, bubby, and that, in my mind, reduces the ability to detect possible problems just by looking at code.
None of this was supposed to matter, of course. When you do clever-schoolboy things like override operator*, this is meant to be to help you provide a nice waterproof abstraction. Golly, j is a Unicode String type, and multiplying a Unicode String by an integer is obviously a good abstraction for converting Traditional Chinese to Standard Chinese, right?
Code: Select all
if( TempClass==SomeBase )
Code: Select all
TempClass=(UClass*)TempClass->SuperField