Same functions different datablocks?
by Dale Harper · in Torque Game Engine · 04/03/2008 (11:49 am) · 5 replies
I'm trying to add more functionality to a scripted swinging door resource I'm working on. I have a StaticShapeData datablock named DoorItem that uses DoorItem::onAdd, DoorItem::onCollision, DoorItem::onDamage and DoorItem::damage functions. I'm adding a second StaticShape door and would like for it to use the same functions that DoorItem is using. Is this possible? Or do I need to create a separate cs file for each door type that I add?
I have tried datablock StaticShapeData(DoorItem2 : DoorItem) This does allow me to use the fields from the original DoorItem but not the functions.
Namespace-es Give Me Headache-es too! I've tried using the className field but all this ever gets me is a syntax error.
I would really appreciate it if someone could at least nudge me in the right direction.
I have tried datablock StaticShapeData(DoorItem2 : DoorItem) This does allow me to use the fields from the original DoorItem but not the functions.
Namespace-es Give Me Headache-es too! I've tried using the className field but all this ever gets me is a syntax error.
I would really appreciate it if someone could at least nudge me in the right direction.
#2
I have tried that! I did try it again after reading your response. I get a syntax error anytime I try to use the className field in a datablock. I know that I must be missing something simple but I can not figure out what it is. The following generates a syntax error at className = "DoorItem";
If I rem out the className line the syntax error goes away.
04/03/2008 (12:34 pm)
Hi mb,I have tried that! I did try it again after reading your response. I get a syntax error anytime I try to use the className field in a datablock. I know that I must be missing something simple but I can not figure out what it is. The following generates a syntax error at className = "DoorItem";
datablock StaticShapeData(DoorItem) // define the door item
{
category = "door";
canSaveDynamicFields = "1";
maxDamage = 100;
shapeFile = "~/data/shapes/door/Door.dts";
};
datablock StaticShapeData(CabinDoorItem)
{
className = "DoorItem";
shapeFile = "~/data/shapes/door/CabinDoor.dts";
};If I rem out the className line the syntax error goes away.
#3
This way I think they would both use the same functions, and the Cabin Door would inherit the fields from the DoorItem. edit: also you probably wouldn't even need to define the className again in the CabinDoorItem since like I said inherits the fields from DoorItem.
04/03/2008 (12:57 pm)
I think what className is used to insert a function namespace in between the StaticShapeData->CabinDoorItem. So it would be StaticShapeData->DoorFunction->CabinDoorItem. Or something like that. Try this:datablock StaticShapeData(DoorItem) // define the door item
{
category = "door";
canSaveDynamicFields = "1";
maxDamage = 100;
shapeFile = "~/data/shapes/door/Door.dts";
className = "DoorFunction";
};
datablock StaticShapeData(CabinDoorItem : DoorItem)
{
className = "DoorFunction";
shapeFile = "~/data/shapes/door/CabinDoor.dts";
};
function DoorFunction::onAdd()
{
...
}This way I think they would both use the same functions, and the Cabin Door would inherit the fields from the DoorItem. edit: also you probably wouldn't even need to define the className again in the CabinDoorItem since like I said inherits the fields from DoorItem.
#4
I really appreciate the help. I will post this swinging door resource as soon as I am finished with it.
04/03/2008 (1:23 pm)
Thank you mb! That worked great. You were right about the className too. It did not need to be defined in the second datablock.I really appreciate the help. I will post this swinging door resource as soon as I am finished with it.
#5
04/03/2008 (6:23 pm)
Nice. glad you got it working
Torque 3D Owner mb
edit:
function DoorItem::onAdd() { ... }datablock StaticShapeData( DoorItem2 ) { className = "DoorItem"; };editted errors in my code ...