Classname in an Object: Okay to rename?
by Demolishun · in Torque 3D Professional · 12/17/2011 (1:02 am) · 2 replies
So I have this code:
The following functions run fine and every object inherits the name space of TestNS. So is this a bad idea? My main purpose for running this code is to test namespace functionality with regards to callbacks created using "Con::addCommand". The runtcb function works fine either defined like above or from a C++ callback. This is one of those areas of TS I just don't quite grasp.
new SimObject(TestNS){
className = TestNS;
};
new SimObject(TestNS2:TestNS){
};
new SimObject(TestNS3:TestNS2){
};
new SimObject(TestNS4:TestNS3){
};
function TestNS::runtcb(%this){
echo("test function");
}
TestNS.runtcb();
echo(TestNS.getClassNamespace());
TestNS2.runtcb();
echo(TestNS2.getClassNamespace());
TestNS3.runtcb();
echo(TestNS3.getClassNamespace());
TestNS4.runtcb();
echo(TestNS4.getClassNamespace());When it executes I get this error: "Error: cannot change namespace parent linkage of TestNS from SimObject to TestNS". The following functions run fine and every object inherits the name space of TestNS. So is this a bad idea? My main purpose for running this code is to test namespace functionality with regards to callbacks created using "Con::addCommand". The runtcb function works fine either defined like above or from a C++ callback. This is one of those areas of TS I just don't quite grasp.
About the author
I love programming, I love programming things that go click, whirr, boom. For organized T3D Links visit: http://demolishun.com/?page_id=67
#2
Okay, you solved something that has bothered me for a while. It never even dawned on me that the classname would collide with the object name. That makes a lot of sense.
I renamed my first object TestNS1 and after that it did not care if I changed the classname to TestNS. Ahh, the little caveats of a very forgiving scripting language.
Thanks for your help.
12/17/2011 (4:26 am)
@dB,Okay, you solved something that has bothered me for a while. It never even dawned on me that the classname would collide with the object name. That makes a lot of sense.
I renamed my first object TestNS1 and after that it did not care if I changed the classname to TestNS. Ahh, the little caveats of a very forgiving scripting language.
Thanks for your help.
Torque Owner Daniel Buckmaster
T3D Steering Committee
new SimObject(TestObject) { className = "SomeClass" };The class hierarchy of TestObject looks like TestObject->SomeClass->SimObject->...(At least, that's the way it used to work... I hope it still works this way in T3D ;P)
Does that help at all?'
EDIT: Changed example a bit to avoid confusion with Frank's example.