Game Development Community

Creating a object class with a datablock?

by Johnathan Moore · in Torque Game Engine · 03/30/2006 (12:46 pm) · 8 replies

Hi,
As the title says im trying to create a new object class with a datablock. Theyre subclasses of simobject and simdatablock. But when it comes to compile the lines implementing the object, in the source, it spews up a load of errors. The datablock on its own compiled without a problem.

Does anyone know why?

Error	25	error C2143: syntax error : missing ';' before '*'	c:\enginemake\engine\game\RTS\RTSSquad.cc	17	
Error	26	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	c:\enginemake\engine\game\RTS\RTSSquad.cc	17	
Error	27	error C2556: 'int *RTSSquad::getClassRep(void) const' : overloaded function differs only by return type from 'AbstractClassRep *RTSSquad::getClassRep(void) const'	c:\enginemake\engine\game\RTS\RTSSquad.cc	17	
Error	28	error C2371: 'RTSSquad::getClassRep' : redefinition; different basic types	c:\enginemake\engine\game\RTS\RTSSquad.cc	17	
Error	29	error C2143: syntax error : missing ';' before '*'	c:\enginemake\engine\game\RTS\RTSSquad.cc	17	
Error	30	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	c:\enginemake\engine\game\RTS\RTSSquad.cc	17	
Error	31	error C2371: 'AbstractClassRep' : redefinition; different basic types	c:\enginemake\engine\game\RTS\RTSSquad.cc	17	
Error	32	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	c:\enginemake\engine\game\RTS\RTSSquad.cc	17	
Error	33	error C2556: 'int *RTSSquad::getStaticClassRep(void)' : overloaded function differs only by return type from 'AbstractClassRep *RTSSquad::getStaticClassRep(void)'	c:\enginemake\engine\game\RTS\RTSSquad.cc	17	
Error	34	error C2371: 'RTSSquad::getStaticClassRep' : redefinition; different basic types	c:\enginemake\engine\game\RTS\RTSSquad.cc	17	
Error	35	error C2143: syntax error : missing ';' before '*'	c:\enginemake\engine\game\RTS\RTSSquad.cc	17	
Error	36	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	c:\enginemake\engine\game\RTS\RTSSquad.cc	17	
Error	37	error C2371: 'AbstractClassRep' : redefinition; different basic types	c:\enginemake\engine\game\RTS\RTSSquad.cc	17	
Error	38	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	c:\enginemake\engine\game\RTS\RTSSquad.cc	17	
Error	39	error C2556: 'int *RTSSquad::getParentStaticClassRep(void)' : overloaded function differs only by return type from 'AbstractClassRep *RTSSquad::getParentStaticClassRep(void)'	c:\enginemake\engine\game\RTS\RTSSquad.cc	17	
Error	40	error C2371: 'RTSSquad::getParentStaticClassRep' : redefinition; different basic types	c:\enginemake\engine\game\RTS\RTSSquad.cc	17	
Error	41	error C2146: syntax error : missing ';' before identifier 'AbstractClassRep'	c:\enginemake\engine\game\RTS\RTSSquad.cc	18	
Error	42	error C2143: syntax error : missing ';' before '*'	c:\enginemake\engine\game\RTS\RTSSquad.cc	18	
Error	43	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	c:\enginemake\engine\game\RTS\RTSSquad.cc	18	
Error	44	error C2371: 'AbstractClassRep' : redefinition; different basic types	c:\enginemake\engine\game\RTS\RTSSquad.cc	18	
Error	45	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	c:\enginemake\engine\game\RTS\RTSSquad.cc	18	
Error	46	error C2556: 'int *RTSSquadData::getClassRep(void) const' : overloaded function differs only by return type from 'AbstractClassRep *RTSSquadData::getClassRep(void) const'	c:\enginemake\engine\game\RTS\RTSSquad.cc	18

#1
03/30/2006 (1:21 pm)
Looks the type of stuff you get when there's and undefined type. Would help to see the code.
#2
03/30/2006 (1:24 pm)
Edit. Updated code below
#3
03/30/2006 (1:31 pm)
No ";" after:
IMPLEMENT_CO_NETOBJECT_V1( RTSSquad )
#4
03/30/2006 (1:40 pm)
O that was a bit stupid,lol, but it still does not work

Header:
//-----------------------------------------------------------------------------
// Torque Game Engine 
//-----------------------------------------------------------------------------

#ifndef _RTSSQUAD_H_
#define _RTSSQUAD_H_

#include "console/SimBase.h"
#include "sim/netConnection.h"
#include "core/bitStream.h"

class RTSSquadData : public SimDataBlock
{
   // This typedef is required for tie ins with the script language.
   //--------------------------------------------------------------------------
      protected:
      typedef SimDataBlock Parent;
   //--------------------------------------------------------------------------

   // This macro ties us into the script engine, and MUST MUST MUST be declared
   // in a public section of the class definition.  If it isn't you WILL get
   // errors that will confuse you.
   //--------------------------------------------------------------------------
   public:
   DECLARE_CONOBJECT(RTSSquadData);
   //--------------------------------------------------------------------------

	  // Constructer Declaration
	  RTSSquadData::RTSSquadData();
	  // Destructer Declaration
      RTSSquadData::~RTSSquadData();

      // These are overloaded functions from SimObject that we handle for
      // tie in to the script language.
      //-----------------------------------------------------------------------
      static void initPersistFields();
	  void packData(BitStream* stream);
      void unpackData(BitStream* stream);

//	private:
//    U32 mMemberVar;      
//	SimObjectPtr<RTSUnit> herohandle;
//	SimObjectPtr<RTSUnit> leaderhandle;
//	U32 squadmembermax;
//	SimObjectPtr<RTSUnit>  member[30];

};



class RTSSquad : public SimObject
{

protected:      
	typedef SimObject Parent;

public:
// Constructer Declaration
	  RTSSquad::RTSSquad();
	  // Destructer Declaration
      RTSSquad::~RTSSquad();

	  bool processArguments(S32 argc, const char **argv);
	  bool onAdd();
   	  void onRemove();
	  // NetObject
      U32  packUpdate  (NetConnection *conn, U32 mask, BitStream *stream);
      void unpackUpdate(NetConnection *conn,           BitStream *stream);

DECLARE_CONOBJECT( RTSSquad );
}

#endif

Source:
//-----------------------------------------------------------------------------
// Torque Game Engine 
//-----------------------------------------------------------------------------
#ifndef _RTSSQUAD_H_
#include "game/RTS/RTSSquad.h"
#endif // _RTSSQUAD_H_

#include "console/SimBase.h"

// This macro is required in order to "tie in" with the scripting engine.
IMPLEMENT_CO_NETOBJECT_V1( RTSSquad );
IMPLEMENT_CO_DATABLOCK_V1( RTSSquadData );

// Just your standard object constructor.  Nothing fancy here.
RTSSquadData::RTSSquadData()
{
//   mMemberVar = 0;

}

// Just your standard object destructor.  Nothing fancy here.
RTSSquadData::~RTSSquadData()
{

}

// Engine Functions

void RTSSquadData::initPersistFields()
{
  Parent::initPersistFields();
}

void RTSSquadData::packData(BitStream* stream)
{
   Parent::packData(stream);

}

void RTSSquadData::unpackData(BitStream* stream)
{
   Parent::unpackData(stream);

}

// Object -----------------------------------------------------

RTSSquad::RTSSquad()
{

}
RTSSquad::~RTSSquad()
{

}

bool RTSSquad::processArguments(S32 argc, const char **argv)
{
if(argc == 0)
return true;
else 
return true;

return false;
}



bool RTSSquad::onAdd()
{
if (!Parent::onAdd())
return false;

return true;
}

void RTSSquad::onRemove()
{
Parent::onRemove();
}
#5
03/30/2006 (2:49 pm)
What are the first 10 lines of the compile log now?
#6
03/30/2006 (3:34 pm)
Your constructor and destructors are wrong in the header file. At first glance, it looked like you tried to inline them, but you also declare them in the source file.

They should look like:
RTSSquadData();
~RTSSquadData();

and
RTSSquad();
~RTSSquad();

in the headers.
#7
03/31/2006 (2:55 am)
You also seem to be missing the semicolon after the closing curly brace of this class:

class RTSSquad : public SimObject
{
...
}
#8
03/31/2006 (9:30 am)
Thanks for the help with all the advice ive got it to compile