Game Development Community

GetClassName() doesn't return specific name

by Yost Engineering · in Technical Issues · 10/24/2007 (2:44 pm) · 3 replies

Hello,

I have a datablock for a simple mesh, like so:

datablock StaticShapeData(AniCow)
{
   category  = "AnimatedObjects";
   shapeFile = "~/data/shapes/Cow/Anicow.dts";
   className = "Cow";
};

In script I want to be able to determine if and item is of this class - I tried using %obj.getClassName() but it always returns "StaticShape" rather than "Cow".
Any suggestions on how to return the specific class name?
Thanks in advance!

#1
10/25/2007 (7:48 am)
SPCA.notify("Yost Engineering","Suspected Cow Tossing");

;)


To give data on the question, getClassName() is tightly tied into the C++ class heirarchy, by default. I'm not sure what happens if you try to override that. Might not be good (might change the "script namespace" for the object). I see that Item objects use a field called classname, and that it is a field of a very basic game class. (No real answers here, sorry.)

If you were to do a %obj.getDataBlock().getName() it would return "AniCow" which might be adequate for your needs. Warning: this only works on the server. Datablock names aren't normally sent to the clients.
#2
10/25/2007 (8:10 am)
GetClassName() returns the class of the object:

WheeledVehicle, Player, and in your case StaticShape. You could do something like:

datablock StaticShapeData(AniCow)
{
   category  = "AnimatedObjects";
   shapeFile = "~/data/shapes/Cow/Anicow.dts";
   type = "Cow";
};

then %obj.type would give you what you want.
#3
05/12/2009 (8:16 am)
For future reference, I think the proper method to get the class of an object as defined here or in the level builder is:

%object.getClassNamespace();

At least this is how it seems to work under TGB 1.7.

-Unk