Game Development Community

Minimum code needed to create a new player

by Justin Mosiman · in Torque Game Engine Advanced · 07/30/2007 (5:05 pm) · 2 replies

Hello,

I am trying to create a new class that has the Player class as its parent, but I am having difficulty getting the game to accept the new class. Right now all that I am trying to do is to create a new class that does not have any new features from Player. So with that, the code that I have:

unit.h:
#ifndef _UNIT_H_
#define _UNIT_H_

#include "game/player.h"

struct UnitData : public PlayerData {
	typedef PlayerData Parent;
	DECLARE_CONOBJECT(UnitData);
};

class Unit : public Player
{
   typedef Player Parent;

private:

public:

	DECLARE_CONOBJECT(Unit);
};

#endif

And unit.cpp:
#include "game/unit.h"

IMPLEMENT_CO_DATABLOCK_V1(UnitData);

IMPLEMENT_CONOBJECT(Unit);

When I start the game in debug mode and try to place a new unit, I get a fatal error saying "out of range class id." from the file core\bitstream.cpp @173. I've searched through the call stack and didn't see anything that relates to unit, so I don't know how to debug next. When creating the new unit, I have the following torque script code:
function serverCmdCreatePlayer(%client){
   %player = new Unit() {
      dataBlock = UnitBody;
      client = %this;
   };
   MissionCleanup.add(%player);

   %player.setTransform("20 20 30 1 0 0 0");
}
The datablock code I just copied from Player, and replaced the name, so that should be okay. To me it looks like I am missing some required code for unit, but I don't know what code that is... because shouldn't unit be inheriting everything from Player?

Any help would be great,
Justin

#1
07/30/2007 (5:18 pm)
IMPLEMENT_CONOBJECT(Unit);
should be
IMPLEMENT_CO_NETOBJECT_V1(Unit);
#2
07/31/2007 (4:07 pm)
Look at the aiPlayer.cpp/h, thats a perfect example of what you are trying to do.