Game Development Community

Getting the datablock name out of getDataBlock()

by Robin Degen · in Torque Game Engine · 03/24/2007 (10:33 am) · 5 replies

For something i am trying to do, i need to get the datablock name using getDataBlock() or "this" from AIPlayer::getAIMove. So if my AI player has a datablock called TestPlayer1, it should return that as a char *. Anybody know?

#1
03/24/2007 (5:11 pm)
On any object you can perform .getName() to get the actual name of an object (if set, otherwise - empty string). Be that datablock or any other object.
e.g.:
echo( %obj.getDataBlock().getName() );
#2
03/25/2007 (7:27 am)
Thanks, but that only works from script. I'm working through the engine source.

PlayerData *TempObj;
TempObj = this->mDataBlock;

TempObj doesnt seem to have a getName. I solved the whole thing by adding a "nametag" to the player datablock and then getting that.
#3
03/25/2007 (7:55 am)
Hmm.. Thats strange.
I've just put this:
PlayerData *TempObj;
   TempObj = this->mDataBlock;
   TempObj->getName();
   mDataBlock->getName();
   this->getDataBlock()->getName();
inside the aiPlayer.cc / bool AIPlayer::getAIMove(Move *movePtr) and it compiled fine (TGE1.5 with VC7.1).
This c++ method "getName()" is easy accessible almost from everywhere in the code.
#4
03/25/2007 (8:15 am)
Yeah, getName () works on all SimObject derives.
#5
03/25/2007 (10:21 am)
Ah, my intellisense database didnt include the getName as part of playerdata, so I expected it not to work. But when i typed it anyway it worked. Thanks guys. I should look into what else is not included in that list...