Game Development Community

Creating a SimObject in C++ land

by Josh Goldshlag · in Torque Game Engine · 05/16/2002 (12:49 pm) · 0 replies

I think I have this working, but I just wanted to make sure I am doing it the right way.

I have a class, call it A. When I call one of A's functions, I want A to create an instance of class B and store the id in a field of class A. Then some script functions can grab the id and do stuff with the new class B.

I currently do the following:

(in initPersistant fields of class A)
addField("results", TypeS32, Offset(mResultID, A));

(in the function in class A)
mResults = new B;
mResults->registerObject();
Sim::getRootGroup()->addObject(mResults);
mResultID = mResults->getId();

This seems to work (ie no memory leaks or crashes, and I can use class B), but I was wondering if it is the right way to go about doing this. I guess I can also take a peek into the script interpreter to see what it does.

Josh