Game Development Community

Stub Class and new class types?

by Johnathan Moore · in Torque Game Engine · 07/16/2006 (6:22 am) · 3 replies

Hi, I need help creating a new object class with a datablock. I expanded on a resource for creating a basic object class.

//-----------------------------------------------------------------------------
// Torque Game Engine 
// Written by John Vanderbeck                                                  


#ifndef _BASICOBJECT_H_
#define _BASICOBJECT_H_

#ifndef _SIMBASE_H_
#include "game/gameBase.h"
#endif
class BasicObjectData : public GameBaseData
{

      protected:
      typedef GameBaseData Parent;

 

   public:
   DECLARE_CONOBJECT(BasicObjectData);
   
      static void initPersistFields();
	  void packData(BitStream* stream);
      void unpackData(BitStream* stream);
private:
    U32 mMemberVar;
	
};





class BasicObject : public GameBase
{
   
	protected:
      typedef GameBase Parent;

   public:
      BasicObject();
      ~BasicObject();

   
 
      bool processArguments(S32 argc, const char **argv);
      bool onAdd();
      void onRemove();
      static void initPersistFields();
 
      void setVariable(int var);
      int sum(int a, int b);
      void doCallback();
   
   private:
      int mMemberVar;      

   
   //--------------------------------------------------------------------------
   public:
   DECLARE_CONOBJECT(BasicObject);
   //--------------------------------------------------------------------------
};

#endif // _BASICOBJECT_H_

#include "game/rts/basicobject.h"

#include "console/simBase.h"
#include "console/consoleInternal.h"

// This macro is required in order to "tie in" with the scripting engine.
IMPLEMENT_CO_DATABLOCK_V1( BasicObjectData );
IMPLEMENT_CONOBJECT(BasicObject);


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

void BasicObjectData::packData(BitStream* stream)
{
   Parent::packData(stream);
}

void BasicObjectData::unpackData(BitStream* stream)
{
   Parent::unpackData(stream);
}


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

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

}

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

   return false;
}

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

   const char *name = getName();
   if(name && name[0] && getClassRep())
   {
      Namespace *parent = getClassRep()->getNameSpace();
      Con::linkNamespaces(parent->mName, name);
      mNameSpace = Con::lookupNamespace(name);
   
   }

   return true;
}

void BasicObject::onRemove()
{
   Parent::onRemove();
}

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


void BasicObject::setVariable(int var)
{
   mMemberVar = var;
}

int BasicObject::sum(int a, int b)
{
   return a + b;
}

void BasicObject::doCallback()
{
   Con::executef(this, 2, "onCallback", "string_variable");
}

ConsoleMethod(BasicObject, setVariable, void, 3, 3, "(int variable) Sets a variable in the BasicObject")
{
   object->setVariable(dAtoi(argv[2]));
}

ConsoleMethod(BasicObject, sum, S32, 4, 4, "(int var1, int var2) sums the two ints")
{
   return object->sum(dAtoi(argv[2]),dAtoi(argv[3]));
}

ConsoleMethod(BasicObject, doCallback, void, 2, 2, "Calls the BasicObject callback script function")
{
   object->doCallback();
}

but now when I try to create it it says
Object 'testify' is not a member of the 'GameBaseData' data block class
source/server/scripts/test.cs (23): Register object failed for object myObject of class BasicObject.
BasicObject = 0
ffh =

#1
07/16/2006 (5:42 pm)
While I haven't tried it, there is an example on TDN called "Code/How do I make an object with a datablock?". It only has one minor difference from yours that I can see.

You have
IMPLEMENT_CO_DATABLOCK_V1( BasicObjectData );
IMPLEMENT_CONOBJECT(BasicObject);

It has
IMPLEMENT_CO_NETOBJECT_V1( ExampleObj);
IMPLEMENT_CO_DATABLOCK_V1( ExampleObjData );
#2
07/17/2006 (5:11 am)
Thats not the problem, it worked before I changed to TSE
#3
07/30/2006 (8:59 am)
Ah I have discovered somthing. I have no idea what it means but I am sure it has somthing to do with this by mucking up the heiricy.

/// Stub class
/// 
/// @note This is a stub class to ensure a proper class hierarchy. No 
///       information was available for this class.
class  testify : public BasicObjectData {
  public:
};

class  ShapeBaseData : public GameBaseData {
  public:
   virtual Script damage() {}
   virtual bool checkDeployPos(Transform xform) {}
   virtual string getDeployTransform(Point3F pos, Point3F normal) {}
   /*!
    */
   caseString category;

could sombody explain?