Error deriving RTSBuildingMarker from StaticShape
by Justin Tolchin · in RTS Starter Kit · 04/13/2005 (12:58 pm) · 3 replies
Hi,
I've added a "build_point" helper node to one of our building .dts files, and I need to be able to call something like this:
object->getShape()->findNode("build_point");
I can do that with an actual RTSUnit object because it inherits from ShapeBase. However, the "build_point" node needs to be accessible *before* the actual building is placed/created (so I can tell the builder where to go to build the thing). At that point all I have is the RTSBuildingMarker, but that class inherits from TSStatic and doesn't have any "findNode" capabilities (as far as I can tell). So to get the functionality I needed, I tried to derive RTSBuildingMarker from StaticShape (which inherits from ShapeBase). But when I do that I get an error during object creation because the datablock field is NULL.
I'm just setting up the datablock like this (in client/scripts/buildings.cs):
and then in the same file (in the startPlaceBuilding function) I create the object like this:
But when I try to run it I get this error: "Object 'csBarracksBlock' is not a member of the 'GameBaseData' data block class". I'm obviously doing something stupid but I can't see it. The only thing I can think of is that even though the datablock is defined in the same script as the "new RTSBuildingMarker" call, the script engine somehow doesn't really "know" about the datablock. Is that possible?
Is there an easier solution to all of this? I'm trying to keep the building marker class purely client-side and use as lightweight an object as possible. I just need to be able to get to that "build_point" node.
Thanks!
I've added a "build_point" helper node to one of our building .dts files, and I need to be able to call something like this:
object->getShape()->findNode("build_point");
I can do that with an actual RTSUnit object because it inherits from ShapeBase. However, the "build_point" node needs to be accessible *before* the actual building is placed/created (so I can tell the builder where to go to build the thing). At that point all I have is the RTSBuildingMarker, but that class inherits from TSStatic and doesn't have any "findNode" capabilities (as far as I can tell). So to get the functionality I needed, I tried to derive RTSBuildingMarker from StaticShape (which inherits from ShapeBase). But when I do that I get an error during object creation because the datablock field is NULL.
I'm just setting up the datablock like this (in client/scripts/buildings.cs):
datablock StaticShapeData(csBarracksBlock)
{
shapeFile = "~/data/shapes/buildings/barracks/barracks.dts";
};and then in the same file (in the startPlaceBuilding function) I create the object like this:
$NewBuilding = new RTSBuildingMarker()
{
dataBlock = csBarracksBlock;
};But when I try to run it I get this error: "Object 'csBarracksBlock' is not a member of the 'GameBaseData' data block class". I'm obviously doing something stupid but I can't see it. The only thing I can think of is that even though the datablock is defined in the same script as the "new RTSBuildingMarker" call, the script engine somehow doesn't really "know" about the datablock. Is that possible?
Is there an easier solution to all of this? I'm trying to keep the building marker class purely client-side and use as lightweight an object as possible. I just need to be able to get to that "build_point" node.
Thanks!
#2
BuildingMarker certainly does have a TSShapeInstance pointer in it. mShapeInstance is what you want.
04/15/2005 (3:55 pm)
Check to see if there's more than one mDatablock field defined in the subclasses...BuildingMarker certainly does have a TSShapeInstance pointer in it. mShapeInstance is what you want.
#3
Thanks for the info. I'll track down the mDatablock weirdness if this doesn't work out.
04/18/2005 (11:22 am)
Oh, ok I didn't realize I could get access to the same stuff from mShapeInstance. Good to know. Although it looks like I need to add an accessor for it since it's protected (I don't know if this was one of them, but it seems like a few things were made protected in TSE that weren't in TGE).Thanks for the info. I'll track down the mDatablock weirdness if this doesn't work out.
Torque Owner Justin Tolchin
This is what I see in the debugger:
RTSBuildingMarker::onAdd is called. At this point mDatablock is NULL.
StaticShape::onAdd is called. mDatablock is still NULL.
ShapeBase::onAdd is called. mDatablock is still NULL.
GameBase::onAdd is called. Somehow mDatablock is now magically a valid value (?!). How does that happen? I can even see the the shapeName field is set to my .dts file.
GameBase::onAdd eventually returns true to ShapeBase::onAdd, but at that point mDatablock magically becomes NULL again. Because of that, ShapeBase::onAdd eventually crashes when it reaches the line "if( mDataBlock->dynamicReflection )..."
Can anyone explain this? I'm stumped. Is there something magical about making a client-side-only version of StaticShape that I'm missing?