cloning objects / class question
by Steve D · in Torque Game Builder · 10/06/2009 (8:58 pm) · 3 replies
Hi everyone - I have this very simple piece of code which is cloning a trigger object and then it's getting mounted on a moving sprite object -
%obj = player_sensormiddle.Clone();
%obj.Mount(%vehicle, "0 0", true, true, true);
%obj.class = "ClassTest";
I have verified the trigger object is getting mounted correctly but the problem is even though I am cloning the trigger it doesn't add it's name or class which is assigned in the editor. When I assign a class name in the code above it never fires a trigger with the code below -
function ClassTest::OnEnter(%this, %obj)
{
echo("trigger test");
}
As a test I mounted a already created trigger on the vehicle and the callback fires off fine. Is there another way to correctly assign a class to an object in script or am I jut doing something wrong here?
And one other question, it seems that if you assign a trigger a name and class (in the editor) it fires the callback on the object name and not the class name? I guess it can only fire 1 callback and looks at the name first, is that right?
%obj = player_sensormiddle.Clone();
%obj.Mount(%vehicle, "0 0", true, true, true);
%obj.class = "ClassTest";
I have verified the trigger object is getting mounted correctly but the problem is even though I am cloning the trigger it doesn't add it's name or class which is assigned in the editor. When I assign a class name in the code above it never fires a trigger with the code below -
function ClassTest::OnEnter(%this, %obj)
{
echo("trigger test");
}
As a test I mounted a already created trigger on the vehicle and the callback fires off fine. Is there another way to correctly assign a class to an object in script or am I jut doing something wrong here?
And one other question, it seems that if you assign a trigger a name and class (in the editor) it fires the callback on the object name and not the class name? I guess it can only fire 1 callback and looks at the name first, is that right?
#2
I even tried not mounting the trigger on the object but just to put it in the middle of the screen where I know the objects will enter it.
I used the original stock trigger I made (to make sure I didn't do anything wrong with it) and placed it in the above location and the OnEnter fires off fine so I know the trigger works and I know my objects are setting off the trigger.
So unless I'm doing something really dumb here I still don't think it works grrrr!
10/07/2009 (9:17 pm)
Hi William, thanks for the well thought out response. What's interesting is it looks like it should work but it doesn't. The echo returns the class name, even in Torsion debug mode when I type in %obj.class I get the class name back but the OnEnter doesn't fire off. I even tried not mounting the trigger on the object but just to put it in the middle of the screen where I know the objects will enter it.
I used the original stock trigger I made (to make sure I didn't do anything wrong with it) and placed it in the above location and the OnEnter fires off fine so I know the trigger works and I know my objects are setting off the trigger.
So unless I'm doing something really dumb here I still don't think it works grrrr!
#3
In one of my previous games, I wrote my own "clone" which new'd up a new object and copied the values that I needed from the original object. This might be something you can do to at least let you move on.
(Just in case you need this, too... You can find the original creation of the object in the .t2d level file, which you can just copy for your version of the clone function.)
10/07/2009 (11:35 pm)
I wouldn't discount a problem with the engine. This thread seems to describe your same problem.In one of my previous games, I wrote my own "clone" which new'd up a new object and copied the values that I needed from the original object. This might be something you can do to at least let you move on.
(Just in case you need this, too... You can find the original creation of the object in the .t2d level file, which you can just copy for your version of the clone function.)
Associate William Lee Sims
Machine Code Games
Looking in the source code, setting the class object like you do ultimately calls "setClassNamespace", which is simply another function you could use, as in "%obj.setClassNamespace("ClassTest");".
Right after the clone and at the end, could you put in an "echo("Class = " @ %obj.getClassNamespace());"? What does it say in the console?
As for your final question, typically the engine goes up the namespace tree to find the function. So if "ObjectName::onEnter" doesn't exist it goes up to "ObjectClass::onEnter", and so on. If you have both functions defined, you can put "Parent::onEnter(%this,%obj);" in the "ObjectName::onEnter".
Let me know what you get for those echoes and maybe that can help us debug the problem. Later!