Game Development Community

Getting the Player Object

by Daniel Neilsen · in Torque Game Engine · 10/26/2001 (6:27 am) · 2 replies

I have this function

void GuiEnergyBarVertHud::onRender(Point2I offset, const RectI &updateRect)
{
GameConnection* conn = GameConnection::getServerConnection();
if (!conn)
return;
ShapeBase* control = conn->getControlObject();
if (!control || !(control->getType() & PlayerObjectType))
return;

mValue = 1 - control->getEnergyValue();


but, instead of running the function ShapeBase::getEnergyValue() for the shapebase I want to run Player::getEnergyValue().

I have the gameconnection and the shapebase. How can I get the player from these?

#1
10/26/2001 (7:06 am)
You'll want to cast the ShapeBase to a player object before calling the function...

Player *controlPlayer = dynamic_cast(conn->getControlObject());

if(controlPlayer)
mValue = 1 - controlPlayer->getEnergyValue();

or, you could do a static cast if you know for sure that the control object is a player.
#2
10/26/2001 (1:08 pm)
Thanks mark
I knew it had to be something simple :)