Game Development Community

Subclassing with ItemData datablocks

by Jonathan Shih · in Torque Game Engine · 08/25/2004 (3:48 am) · 7 replies

I want to have the following hierarchy set up:

datablock ItemData(WeaponData) {
    className = Weapon;
    ...
}

datablock ItemData(RangedWeapon : WeaponData) {
    ...
}

datablock ItemData(Bow : RangedWeapon) {
    ...
}

Let's say that a function foo() is implemented for the Weapon class and reimplemented in RangedWeapon. When I want to called Bow::foo(), it goes straight to Weapon::foo() without even looking in the RangedWeapon class.

Does anyone know why this happens and how I can make it follow the class tree correctly?

#1
08/25/2004 (2:24 pm)
In the Bow::foo and the RangedWeapon::foo funcitons just call Parent::Foo. I'm not sure if your hierarchy is set up correctly.
#2
08/25/2004 (2:45 pm)
It doesn't work. Bow doesn't recognize RangedWeapon as a parent. It still goes straight to the Weapon class. I wonder if I am using 'className' incorrectly. But if I take out that line, it will skip both the RangedWeapon and Weapon classes and look straight for ItemData::foo(). If I add classname=RangedWeapon to the RangedWeapon datablock, it will fail to register the RangedWeapon class.

I'm using Release 1.2.2. Maybe it's a bug from this release version?
#3
08/25/2004 (3:24 pm)
Remember that script is not C++.

It simulate OO only.
#4
08/25/2004 (3:40 pm)
So I guess there's no way to do this, huh?
#5
08/25/2004 (3:48 pm)
Try classname = RangedWeapon in the bow block, and classname = Weapon in the RangedWeapon data.
#6
08/25/2004 (8:08 pm)
RangedWeapon's className is already Weapon, inherited from the WeaponData datablock. RangedWeapon, however, can't be registered as a class.

I think I'll just do my item classing a different way.
#7
08/27/2004 (1:43 am)
www.garagegames.com/docs/torque/general/ch05s04.php Scroll down to 'namespace inheritence'. I see two different ways to accomplish what you need.