Game Development Community

Derived Datablock

by Robert Brower · in Torque Game Engine · 01/29/2003 (12:30 pm) · 3 replies

Hello. I'm trying to figure out how to derive one datablock from another so I can have multiple shapes with the same behavior. I want to call the parent datablock member functions that the child datablocks override like this:

datablock ItemData(MyItem1)
{
shapeFile = "item1.dts";
// values here, omitted for brevity
};

function MyItem1::onCollision()
{
echo("MyItem1::onCollision()");
// do something, omitted for brevity
}

datablock ItemData(MyItem2 : MyItem1)
{
shapeFile = "item2.dts";
// values here, omitted for brevity
};

function MyItem2::onCollision()
{
echo("MyItem2::onCollision()");
Parent::onCollision()
}

Parent::onCollision() in MyItem2::onCollision() doesn't seem to invoke MyItem1::onCollision(). Any ideas? I'm real unclear on how this works. I have searched the forums but I have not been able to get this working. Do I need a package? Is this even possible? I am getting conflicting views.

Thank you,

Robert

#1
01/29/2003 (3:38 pm)
OK... this is not possible. The only thing that deriving a datablock does is copy the data of the parent and allows you to add data. I don't know how I got off onto what I was trying to do. Sometimes I got to laugh. TY Zoomba.
#2
03/28/2003 (9:42 pm)
You can find an example of you case in the example game.

1. Player DataBlock "LightMaleArmor" has a super class "Armor"

you maybe then create other datablock "heavyMailArmor", based on LightMaleArmor" too,
Or create a "FemaleArmor" Based on "Armor" etc.

The Datablock member "ClassName" seems to tell what its superclass is.

2. "Crossbow" and "Rifle" Datablock are "ItemData" Datablocks. And at the Same time, they are subclasses of "Weapon" Datablock too. (You Can See When Rifle.onUse, Crossbow.OnUse is called, the function acturally ran is Weapon.onUse.

I don't fully understand the way how datablock is subclassed. So maybe I am wrong some ways. Hope someone would point out my mistakes. :)
#3
03/30/2003 (1:19 am)
I have read somewhere in the forum, but I don't remember where, that there shuold be a superclass (or superclassname, or perhaps is ClassName as Yui Chung said but I'm not sure) variable in the datablock, so you should do

datablock ItemData(MyItem2 : MyItem1)
{
superclass = "MyItem1"
shapeFile = "item2.dts";
// values here, omitted for brevity
};

now when you call Parent::onCollision it should call MyItem1::onCollision
I haven't tried it, I hope it works, if so tell me.