Game Development Community

How to find Parent Class ID from Data Block ID?

by Jeff Leigh · in Torque Game Engine · 01/17/2003 (4:11 am) · 6 replies

Can anyone tell me how to determine the main "ObjectID" if you only know it's Data Block ID, or even more to the point how I call a function one level up in a class heirarchy (from script that is)?

For example I have this code to create an object:

%player = new AIPlayer() {
      dataBlock = Soldier;
   };

and this code to define an event for the base class:

function AIPlayer::onSomething(%this)
{
%data = %this.getDataBlock();
...
}

And this code to define an event for the derived Soldier data block class:

function Soldier::onSomething(%this)
{
%aiPlayerThis = ????
...
}

When the Soldier::onSomething() event gets called it gets passed the %this ID for the class (i.e. Data Block) which I believe is the same value that you get when querying with getDataBlock() from the original AIPlayer class above.

So, how do I:
1) Reverse that query and determine the parent class's %this value from the Soldier::onSomething() function AND/OR
2) Call the AIPlayer::onSomething() function from the Soldier::onSomething() function.

I know once I have #1 I can call #2 using that but I'd still like to do it directly if I can.

Hope this is clear.

#1
01/17/2003 (4:31 am)
Look at this: www.garagegames.com/docs/torque.sdk/engine/Console.php#ConNamespace
So, in essence, you should be able to call the parents' function with
function Soldier::DoSomething(%this)
{
     Parent::doSomthing(%this);
}
#2
01/17/2003 (6:54 am)
if you need to ObjID as in the number you see when you enter the editor and select an item, you would call obj.getID(); and this will give you the number you need.

So, if you can find the data block then you can find the ID.

Sam
#3
01/18/2003 (3:51 am)
Thanks Stefan, you got me past my dope slap (I wasn't passing %this to Parent::doSomething assuming it was being done for me) BUT this isn't quite getting me where I want to go. Because Soldier is the data block associated with AIPlayer, and not a child class, a call to Parent::doSomething(%this) from Soldier::doSomething() tries calling the parent function of the data block (i.e. PlayerData::doSomething).

I'm trying to get to AIPlayer::doSomething() from it's data block's Soldier::doSomething(). Any other ideas? Anybody?
#4
01/18/2003 (8:27 am)
The datablock hierarchy is separate from the objects hierarchy. Calling Parent::doSomething from a Soldier's datablock method will try to invoke the AIPlayerData::doSomething method, not the AIPlayer::doSomething method (which is on the object, not the datblock)... as it turns out though, AIPlayer does not have a datablock, so it will end up calling PlayerData::doSomething().

AIPlayer doesn't have a datablock because it was setup to use Player datablocks directly.
#5
01/18/2003 (4:38 pm)
Thanks Tim. Can you confirm my understanding of Data Blocks in general then.

As I understand it data blocks are a special storage area used to pass network data and are the same for every instance of a class they are assigned to. This data should remain static and any information that has to change from individual instance to individual instance (like the current health level of a unit) should be put in the C++ classes (i.e. Player and AIPlayer)?

Or is there a way to derive classes right in script to store instance data?
#6
01/18/2003 (5:22 pm)
Your summary is correct, and the individual instance data on a class is usually includes some code in the object pack/unpack methods to make sure the clients are updated.

You can store server side instance data on the objects themselves by using %obj.data = x; This script level instance data is not synchronized with the client, but still comes in usefull in a number of circumstances.