Game Development Community

Creating new c++ class

by Justin Mosiman · in Torque Game Builder · 02/01/2009 (5:22 pm) · 4 replies

Hello,

I am trying to create a new class in C++ and call it from TorqueScript, but I'm having some problems.

First, my C++ .h/.cc file looks like:
ObjectManager.h
#ifndef _OBJECTMANAGER_H_
#define _OBJECTMANAGER_H_

#ifndef _CONSOLEOBJECT_H_
#include "console/consoleObject.h"
#endif

class ObjectManager : public ConsoleObject
{
public:
	typedef ConsoleObject Parent;

	ObjectManager();

	DECLARE_CONOBJECT(ObjectManager);
};

#endif

ObjectManager.cc:
#include "console/console.h"
#include "game/objectManager.h"

IMPLEMENT_CONOBJECT(ObjectManager);

ObjectManager::ObjectManager(){
	Con::errorf("ObjectManager");
}

I tried calling it in script with:
$objectManager = new ObjectManager(){};

But I am getting the error:
Unable to instantiate non-conobject class ObjectManager.

I thought that if I had the IMPLEMENT/DECLARE macros that would fix it, but no luck.

What else do I have to do to create a new class?

Thanks,
Justin

#1
02/01/2009 (6:13 pm)
I would imagine that you need to derive from SimObject instead of ConsoleObject.
#3
02/01/2009 (8:38 pm)
Thank you! That tutorial helped (switching it to SimObject made it work)
#4
02/02/2009 (8:48 am)
If you have any further questions then don't hesitate to ask.

Melv.