Game Development Community

Console Iheritence and namespaces

by Devboy · in Torque Game Engine · 03/02/2004 (4:58 am) · 1 replies

Hi,

I'm trying to create a generic Action datablock class in such a way that every 'named' datablock I create from it will have a different onAction() method.

I have class Action : public simDataBlock and did the following in the script...

datablock Action(MoveAct)
{
    //blah blah
    className = someNameSpace; //I got this from starter.fps
    //blah blah
}

function someNameSpace::onAction(%this, %stuff)
{
   //does something
}

Then I call from somwhere within the C++ code (this is approximate, can't remember what exactly I did here but it finds the relevant datablock for sure!!) :

pSimObj = Sim::findObject("MoveAct"); //hardcoded for testing
Con::executef(pSimObj, 2, "onAction", param);

The function onAction() does not get calle. From what I saw the engine treats the retrived SimObj as belonging to namespace 'Action' (if this has any bearing). The reason I believed this would work is the following bit of codes cut-pasted from starter.fps.
// Add the Ammo namespace as a parent.  The ammo namespace provides
   // common ammo related functions and hooks into the inventory system.
   className = "Ammo";

//Then there's 
function Ammo::onPickup(%this, %obj, %shape, %amount)
{
   // The parent Item method performs the actual pickup.
   if (Parent::onPickup(%this, %obj, %shape, %amount)) {
      serverPlay3D(AmmoPickupSound,%obj.getTransform());
   }
}


note that I couldn't find a declaration for an 'Ammo' namespace anywhere else in the code.

Can anyone explain why I don't get the same results as starter.fps. Or suggest a better way to do what I'm trying to?

Thanks

#1
03/02/2004 (12:20 pm)
For anyone who's wondering what the hell I'm talking about... Only GameBaseData add the functionality for linking a namespace inbetween 'myself' and my parent. Since I needed a lightweight datablock I didn't use it but instead inherit directly from SimDataBlock. The relevant bit of code that fixed this is GameBaseData's onAdd() (I just copy-pasted it and added the namespace variable and field in initPersistFields(). I got my answers from the following resource, which has a very good explantion that in my opinion should go into the new docs:

www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=2212