Game Development Community

Understanding datablocks and inheritance

by daffodilistic · in Torque Game Builder · 11/09/2010 (4:34 am) · 1 replies

Hi all,

according to http://tdn.garagegames.com/wiki/TorqueScript/Namespaces, I should be able to call CrossbowAmmo.onPickup, and it should call Ammo.onPickup. Simplifying the code from the article:

datablock SimDataBlock(CrossbowAmmo)
{
   className = "Ammo";
   dummyVal = 1;
};

function Ammo::onPickup(%AmmoDB) 
{
   echo ("Calling Ammo::onPickup () ==> on ammo DB" SPC %AmmoDB);    
}

%test = new SimObject("TestClass")
{
   datablock = "CrossbowAmmo";
};

%test.onPickup();

I get the error:
Unknown command onPickup.
  Object TestClass(1358) TestClass -> SimObject

Is the article outdated, or am I doing things wrongly here?

#1
11/09/2010 (1:59 pm)
You aren't calling onPickup on the datablock in your code above, you are calling it on the SimObject.

Something like this should work I think:

%test = new SimObject("TestClass")  
{  
   datablock = "CrossbowAmmo";  
};  
  
%test.datablock.onPickup();


Assigning a datablock to an object doesn't cause the object to inherit the information in the datablock, it just assigns the datablock to the object.

Hope that makes sense.