Game Development Community

How can i access mDataBlock variables from within getNextMove??

by Highlander · in Torque Game Engine · 05/22/2007 (11:58 pm) · 8 replies

Is it possible to access mDataBlock variables for a player shape from within:

bool GameConnection::getNextMove(Move &curMove) of gameConnectionMoves.cc?

#1
05/23/2007 (10:31 am)
Sure,

if (mControlObject.isNull() == false)
{
   Player* playerObj = dynamic_cast<Player*>(mControlObject);
   if (playerObj)
   {
      // do stuff
   }
}

This is assuming you are interested in the Player that is currently the control object (the object the client/user is in control of).
#2
05/23/2007 (1:56 pm)
Hi Robert,

Thanks for the reply. I put this into getNextMove:

if (mControlObject.isNull() == false)
{
Player* playerObj = dynamic_cast(mControlObject);
if (playerObj)
{
Con::printf("mDataBlock->minRunEnergy = %f", mDataBlock->minRunEnergy);
}
}

I am thinking that we are not working in the same file. Heres what I get:

Compiling...
gameConnectionMoves.cc
..\engine\game\gameConnectionMoves.cc(242) : error C2065: 'Player' : undeclared identifier
..\engine\game\gameConnectionMoves.cc(242) : error C2065: 'playerObj' : undeclared identifier
..\engine\game\gameConnectionMoves.cc(242) : error C2061: syntax error : identifier 'Player'
..\engine\game\gameConnectionMoves.cc(245) : error C2065: 'mDataBlock' : undeclared identifier
..\engine\game\gameConnectionMoves.cc(245) : error C2227: left of '->minRunEnergy' must point to class/struct/union/generic type
type is ''unknown-type''
#3
05/23/2007 (2:14 pm)
Try including game/Player.h in the header file for GameConnection
#4
05/23/2007 (3:02 pm)
Hi Peter,

Closer!! Now I get this:

Compiling...
gameConnectionMoves.cc
..\engine\game\gameConnectionMoves.cc(248) : error C2682: cannot use 'dynamic_cast' to convert from 'SimObjectPtr' to 'Player *'
with
[
T=ShapeBase
]
..\engine\game\gameConnectionMoves.cc(251) : error C2065: 'mDataBlock' : undeclared identifier
..\engine\game\gameConnectionMoves.cc(251) : error C2227: left of '->minRunEnergy' must point to class/struct/union/generic type
type is ''unknown-type''
#5
05/23/2007 (3:32 pm)
if (mControlObject.isNull() == false)
   {
      Player* playerObj = dynamic_cast<Player*>(&*mControlObject);
      if (playerObj)
      {
         GameBaseData* data = playerObj->getDataBlock();
         PlayerData* playerData = dynamic_cast<PlayerData*>(data);
         if (playerData)
         {
            F32 runEnergy = playerData->minRunEnergy;
            
            // do stuff
         }
      }
   }
#6
05/23/2007 (3:40 pm)
Hi Robert,

great, it works!! thanks!! Im also stuck on how to get at the triggers from within getNextMove(Move &curMove)?

I tried these but no luck:

Con::printf("trigger1 = %d", mTriggerCount[1]);
Con::printf("trigger2 = %d", curMove->trigger[2]);

Thanks for the help!
#7
05/23/2007 (4:33 pm)
This seems like it should work, but the values dont change when i push buttons

Con::printf("trigger1 = %d", curMove.trigger[0]);
Con::printf("trigger2 = %d", curMove.trigger[1]);
Con::printf("trigger3 = %d", curMove.trigger[2]);
Con::printf("trigger4 = %d", curMove.trigger[3]);
#8
05/23/2007 (4:38 pm)
OK this works, although its beyond me

Con::printf("trigger1 = %d", MoveManager::mTriggerCount[0] & 1);
Con::printf("trigger2 = %d", MoveManager::mTriggerCount[1] & 1);
Con::printf("trigger3 = %d", MoveManager::mTriggerCount[2] & 1);
Con::printf("trigger4 = %d", MoveManager::mTriggerCount[3] & 1);