Game Development Community

Deleting an object

by Christian · in Torque Game Engine · 01/06/2007 (1:40 pm) · 4 replies

I'm trying to delete an object, i've tried it as a tsstatic, item, now staticshape. The first part of the code loads it fine, but when the function 'deletedragon comes, it has an error for the %obj.delete; What am I doing wrong?



new StaticShape(%obj)
            {
                position = %impObj_pos;
                rotation = "1 0 0 0";
                scale = "1 1 1";
                dataBlock = "SimpleTarget0";
            };

function deletedragon(%obj)
{
%obj.delete;
}

#1
01/06/2007 (1:50 pm)
Hi,
I'm not sure if an object can delete itself, but even if it could that wouldn't work because you need to add ( ) parentheses after the function name.
function deletedragon(%obj)
{
%obj.delete();
}
I think that will do it.
#2
01/06/2007 (2:35 pm)
I think the %obj that is going to the 2nd function is not bringing the actual object over. Because no matter what I do to it in the 2nd function it does nothing. Any sugs?
#3
01/06/2007 (3:06 pm)
Is %obj a name? a string of characters before its put into StaticShape()?

Im guessing what you actually wanted to do is
%obj = new StaticShape()
{
etc..
};

From there you can

deleteDragon(%obj);

but i recommend using schedule. call:
%obj.schedule(0,"delete");
#4
01/06/2007 (6:42 pm)
Ah works great, ty.