Game Development Community

Creating SimObjects on the C++ side

by Andrew Haydn Grant · in Torque Game Engine · 03/15/2005 (11:52 am) · 2 replies

I would like to create a variety of SimObjects dynamically on the C++ side of things, rather than in script. A lot of hidden mojo happens when I create an object from script. Could anyone out there tell me how to do the following in C++? I can create objects that *mostly* work, but cause asserts much later in the program. I'm sure I am missing other basics, so I am hoping that there is some stock answer already known to the gurus. :-)

%player = new Player() 
  {
    scale = "10 10 10";
    dataBlock = handymanBlock;
    shapeFile = "~/data/shapes/player/player.dts";
  };

#1
03/15/2005 (12:15 pm)
Just call "registerObject()" on your new object and you are ready to go. You can use the "deleteObject()" helper to not only unregister the object "unregisterObject()" but to also delete it.

// Create some object.
someObject* pObject = new someObject();
// Register it.
pObject->registerObject();
// Ready to rock...
...
// Unregister it and destroy.
pObject->deleteObject();

- Melv.
#2
03/15/2005 (1:38 pm)
For some objects, I also need something like:

PlayerData* ppd = dynamic_cast( Sim::findObject("foo") );
pObject->setDataBlock(ppd);

to save me from problems in pack() and unpack().

It's good to know that there is a lot less mojo than I expected. Thanks, Melv!