Author Topic: Namespace Linking  (Read 587 times)

Code: [Select]
function DatablockOne::doSomething(%this, %obj, %arg)
{
// Really long and complicated code.
}

function DatablockTwo::doSomething(%this, %obj, %arg)
{
return DatablockOne::doSomething(%this, %obj, %arg);
}

DatablockTwo.doSomething(%obj, true);

The above code will work. DatablockTwo will completely emulate DatablockOne's functionality. In fact, %this in DatablockOne's function will properly reference DatablockTwo, if DatablockTwo is what was originally called.


Can anyone think of a reason this code should not be used?

I did a little bit more research.

As it turns out, datablocks have a property called className. This is similar to class and superClass for Scriptobjects.

Since most people copy/paste datablocks for editing, almost all images in the game have the className set to "WeaponImage", and items set to "Weapon". This means Weapon::functionName would apply to almost every item in the game.

The functionality is the same as what I've posted, but it doesn't have the overhead of another function call, and needs less maintenance (such as a change in argument counts).

Code: [Select]
function DatablockGroup::doSomething(%this, %obj, %arg)
{
// Really long complicated code.
}

datablock DatablockType(DatablockOne) {
className ="DatablockGroup";
};

datablock DatablockType(DatablockTwo : DatablockOne) {
className ="DatablockGroup";
};

This is identical to what it's OP.

Very nice Iban, good finds :)
Thanks for the info.

As it turns out, datablocks have a property called className. This is similar to class and superClass for Scriptobjects.
Yes they do, it's actually very useful. For example, I use it in my CTF gamemode:

I make a bunch of datablocks like so:
Code: [Select]
for(%i=0; %i < $Slayer::Server::CTF::MaxFlags; %i++)
{
datablock ItemData(flagItem)
{
className = slyrCTF_FlagItem;

//STUFF
};
flagItem.setName("slyrCTF_Flag" @ %i @ "Item");
}

Then I can use a single namespace, slyrCTF_FlagItem, in all of my functions and it will work for all datablocks with that classname.