Game Development Community

Casting Object Types.

by Kimberly Unger · in Torque Game Engine · 03/05/2004 (2:51 pm) · 5 replies

Is it possible to 'cast' an Object from one type to another? Say you want to change a Player Object to a Flying Vehicle type, can this be done?

#1
03/05/2004 (2:59 pm)
Not if your talking about scripts, because as far as I know, that is a typeless language. Also Player is not associated with Vehicle (they have the same parent I think, but thats about it), so you wouldnt be able to do it in C++ either (as far as I know at least, im no expert).
#2
03/05/2004 (3:04 pm)
You can't just arbitrarily change one object type to another, but you can work "up the chain" of inheritance. AFAIK the script language does it automaticly.
#3
03/08/2004 (7:32 am)
You could downcast in the C++ code, but you won't gain anything from it. You'll only lose functionality that you probably need.
#4
03/08/2004 (8:04 am)
Thanks for the info, I'll find another way to handle my problem.
#5
03/11/2004 (6:51 am)
In C++ I tend to dynmaically cast things a lot, especially datablocks
getDataBlock useally will return a shapebase but it can be converted to a player db if needed. Im at work and don't have the full code but it looks something like
GameConnection* conn = getGameConnection();

ShapeBaseData*  shape = conn->getDataBlock();

PlayerData* playerDB = static_cast<PlayerData*> shape;

if(playerDB == NULL)
return;
again I am not certain if this is exactly how I was doing it but look in the code base for static and dynmaic cast