Game Development Community

Displaying an objects name

by Erik Madison · in Torque Game Engine · 09/30/2002 (4:33 pm) · 9 replies

This is very minor, but being the non-coder I am, I was pretty darn proud I got it working.
This will display an items name above it, just like players names are. You can accomplish it via scripts with setshapename, but those are only displayed on repops. I wanted them to show from the initial load.

In \console\CompiledEval.cc, function *CodeBlock::exec(), near the end of it (line 615 normally)
....
dataBlock->deleteObject();
ip = failJump;
break;
}
// Verify a new item being loaded is an item, and has a name. If so, set the name to the shape
if(currentNewObject->getName() && currentNewObject->getClassName() == "Item") {
//Con::printf("Adding object %s of type %s", currentNewObject->getName(), currentNewObject->getClassName());
ShapeBase * shape = static_cast(currentNewObject);
shape->setShapeName(currentNewObject->getName());
}
// end of addition

U32 groupAddId = intStack[UINT];
SimGroup *grp = NULL;
....

These are the names you set in the editor, not the pickup names. Also, it probably should be adjusted to be a different color, and fade from view at a much shorter distance (handled in \fps\guiShapeNameHud.cc).

#1
09/30/2002 (4:38 pm)
heh
instead of hacking this Major function...
why not just use the onAdd for the object?
#2
09/30/2002 (4:58 pm)
*grin* I never really considered that function, as there are only 3 references to it in the sample, none of which really gives any insight (other than an obvious name of course) to its use.
#3
07/07/2009 (6:05 am)
I tried

function Coin::onAdd(){

echo ("coin added"); 

%this.setShapeName("a coin"); 
}

for my coin. It does echo "coin added" in console, but I am not getting the name of the object above it.

Any pointers?
#4
07/07/2009 (6:43 am)
@Nmuta: try this
function Coin::onAdd(%this, %obj)
{
   echo ("coin added"); 
   %obj.setShapeName("a coin");
}
%this would be the object's datablock
%obj would be the object instance itself -- which is what setShapeName needs.
#5
07/07/2009 (6:47 am)
@ Michael Yeah, actually I looked up onAdd() and I tried that right after I posted....no dice.

#6
07/07/2009 (6:51 am)
Mind you, I have NOT done the C++ mod listed above. Maybe I should just do that.
#7
07/07/2009 (7:07 am)
Weird, works for me for just about everything (all shapebase items).
i167.photobucket.com/albums/u143/heretek/screenshot_001-00001.png
#8
07/07/2009 (7:09 am)
Could it be because I am using AFX, and AFX by default does NOT display names above anything ? (even characters?) maybe there's a mod inside of the AFX engine that prevents names from appearing above characters.

I am using AFX in TGE 1.5.2

If so, any pointers on getting those shapenames to display again?
#9
07/07/2009 (8:39 am)
Ok, I was right, in AFX they had removed something in playGui.gui that displays the shapenames of objects.

Luckily Jeff was able to give me a heads up on this . here's the quick fix:
http://www.garagegames.com/community/forums/viewthread/96395