Code: Select all
class'ClassNameHere'
How would this be made generic?
EG:
Code: Select all
function ChildOf(name className) {
return classIsChildOf(self.class, class'valueOfClassName');
}
Code: Select all
class<Pawn>
Any ideas?
Code: Select all
class'ClassNameHere'
Code: Select all
function ChildOf(name className) {
return classIsChildOf(self.class, class'valueOfClassName');
}
Code: Select all
class<Pawn>
IsA
:
Code: Select all
if (SomeObject.IsA('ClassName')) {
...
}
Code: Select all
static function bool HasInventoryObj(Actor actor, class<Inventory> invClass, out Inventory inv, optional bool bNoSubclass) {
for(inv=actor.inventory; inv!=None; inv=inv.Inventory) {
if(class'TypeHelper'.Static.classIsRelatedTo(invClass, inv.class, bNoSubclass) != -1) {
return true;
}
}
inv = None;
return false;
}
/*
* Return:
* -1 - if firstClass is not relationed to secondClass
* 0 - if firstClass is the same class as secondClass
* 1 - if firstClass is a child of secondClass
* 2 - if firstClass is a parent of secondClass
*/
static function int classIsRelatedTo(class firstClass, class secondClass, optional bool bNoSubClass) {
//Log(firstClass@secondClass@firstClass == secondClass);
if(firstClass == secondClass) {
return 0;
}
if(!bNoSubClass) {
if(classIsChildOf(firstClass, secondClass)) {
return 1;
} else if(classIsChildOf(secondClass, firstClass)) {
return 2;
}
}
return -1;
}
Isn't this used to instantiate an instance of a given object, by name, not get a class<Class1> style reference?
Code: Select all
DeathMatchPlus.uc - Line: 1054
Code: Select all
function GiveWeapon(Pawn PlayerPawn, string aClassName )
{
local class<Weapon> WeaponClass;
local Weapon NewWeapon;
WeaponClass = class<Weapon>(DynamicLoadObject(aClassName, class'Class'));
if( PlayerPawn.FindInventoryType(WeaponClass) != None )
return;
newWeapon = Spawn(WeaponClass);
if( newWeapon != None )
{
newWeapon.RespawnTime = 0.0;
newWeapon.GiveTo(PlayerPawn);
newWeapon.bHeldItem = true;
newWeapon.GiveAmmo(PlayerPawn);
newWeapon.SetSwitchPriority(PlayerPawn);
newWeapon.WeaponSet(PlayerPawn);
newWeapon.AmbientGlow = 0;
if ( PlayerPawn.IsA('PlayerPawn') )
newWeapon.SetHand(PlayerPawn(PlayerPawn).Handedness);
else
newWeapon.GotoState('Idle');
PlayerPawn.Weapon.GotoState('DownWeapon');
PlayerPawn.PendingWeapon = None;
PlayerPawn.Weapon = newWeapon;
}
}
Code: Select all
LevelName1 = Caps(Right(LevelName1,J))$".StuffTweaker";
LevelName1 = "P_"$LevelName1;
log ("Old module and Target class is called >"@LevelName1,'NavAdder');
Module1 = Class<Actor>( DynamicLoadObject(LevelName1, class'Class',True) );
if ( Module1 == None )
{
log ("Old common modules unavailable...",'NavAdder');
}
else
{
log ("Found an old tweaking module, attempt loading... "$Module1,'NavAdder');
Spawn(Module1);
if ( Module1 != None )
{
if ( Level.NetMode == NM_ListenServer || Level.NetMode == NM_DedicatedServer )
AddToPackageMap( string(Module1.Outer.Name) );
log ("Old Module has been started...",'NavAdder');
}
else
{
log("BORK - UNABLE To Load old Module !",'NavAdder');
}
}
It returns a class reference from the class name given as a String input parameter (and prior to this it loads corresponding object from the package).1337GameDev wrote: ↑Sun Feb 28, 2021 6:34 am Isn't this used to instantiate an instance of a given object, by name, not get a class<Class1> style reference?
Hmm, does "DynamicLoadObject" create an instance? It seems not...
IsA
:DynamicLoadObject
is only meant to load objects dynamically from a string (not a name), with this string being the full reference to that object (package + name).Class
is also itself an Object (just like in Java, everything is an object extending from Object, whether this is exposed by UScript or not [native]), meaning that one of the things it can load is indeed a class reference, but it can load pretty much any kind of object.IsA
, and you don't need anything else, it's that simple.Code: Select all
local string ClassNamesToLook[8];
local int i;
local float r;
local Actor a;
r = 30.0;
for(i=0; i<32; i++) {
foreach VisibleCollidingActors(class 'ClassNamesToLook[i]', a, r, self.Location) {//obv I cannot access the class name like this
//do something with the found actor here - based on class name
}
}
Code: Select all
local class<Actor> ClassNamesToLook[8];
local int i;
local float r;
local Actor A;
r = 30.0;
foreach VisibleCollidingActors(class'Actor', A, r, self.Location)
{
for (i=0; i<ArrayCount(ClassNamesToLook); i++)
if (A.Class==ClassNamesToLook[i])
Break;
if (i==ArrayCount(ClassNamesToLook))
Continue;
// do something with...
}
Code: Select all
local Name ClassNamesToLook[8];
local int i;
local float r;
local Actor A;
r = 30.0;
foreach VisibleCollidingActors(class'Actor', A, r, self.Location)
{
for (i=0; i<ArrayCount(ClassNamesToLook); i++)
if (A.Class.Name==ClassNamesToLook[i])
Break;
if (i==ArrayCount(ClassNamesToLook))
Continue;
// do something with...
}
ClassIsChildOf(A.Class, ClassNamesToLook[i])
and A.IsA(ClassNamesToLook[i])
respectively, instead of A.Class==ClassNamesToLook[i]
and A.Class.Name==ClassNamesToLook[i]
.