Creating a new Object with a simset as a member variable
by William Hilke · in Torque Game Builder · 06/07/2006 (8:21 pm) · 5 replies
When trying to create a new object that is a child of ScriptObject, and in the constructor creating a "new simset()" variable the object's class is being set to SimSet for some reason.
here is a test case to try it out against RC1.
The above code block will have getClassName() == "SimSet" and there is no printout of the class/superclass. The dump will not show mTestVar as a tagged Field. However mTestSet will be a tagged field with an object id. It will also dump out SimSet methods, along with the other default methods of SimObject.
This code block will have getClassName() == "ScriptObject" and the class will be set to "Test". The tagged fields of the dump will show both mTestVar and mTestSet equal to 0. The dumped functions will be that of ScriptObject.
Are you not supposed to be able to create SimSet/SimObject type objects within the constructor of an object? This seems like a bug to me, but I didn't try and dive into the engine side to figure it out.
here is a test case to try it out against RC1.
%var = new ScriptObject()
{
class = Test;
mTestVar = 0;
mTestSet = new SimSet();
};
echo(%var.getClassName());
%var.dump();The above code block will have getClassName() == "SimSet" and there is no printout of the class/superclass. The dump will not show mTestVar as a tagged Field. However mTestSet will be a tagged field with an object id. It will also dump out SimSet methods, along with the other default methods of SimObject.
%var = new ScriptObject()
{
class = Test;
mTestVar = 0;
mTestSet = 0;
};
echo(%var.getClassName());
%var.dump();This code block will have getClassName() == "ScriptObject" and the class will be set to "Test". The tagged fields of the dump will show both mTestVar and mTestSet equal to 0. The dumped functions will be that of ScriptObject.
Are you not supposed to be able to create SimSet/SimObject type objects within the constructor of an object? This seems like a bug to me, but I didn't try and dive into the engine side to figure it out.
#2
06/07/2006 (9:32 pm)
I understand TorqueScript isn't really an OO language, but for the namespace to get corrupted like this shouldn't go unchecked. It could be a pretty subtle bug that end users pull their hair out over.
#3
06/07/2006 (9:47 pm)
Yeah it should have some sanity checks before returning the handle to the new object. But I hate to second guess the torquescript designers, not having dived into the c++ source very much, either.
#4
06/08/2006 (6:20 am)
It's a good rule of thumb to not do function calls inside an object definition like that.
#5
06/08/2006 (8:17 am)
I would not call a "new SimSet()" call, a function call. Its a variable initialization. That's what the object definition is for, defining member variables.
Torque Owner Alex Rice
Default Studio Name