Deleting all objects of a specific class?
by Dennis Harrington · in Torque Game Builder · 02/18/2007 (3:16 pm) · 7 replies
Hi there - As the title says, is there a way to do this? I'm creating a large number of sprites that I'll want to remove at some point. Is there a way to delete the whole class or do I need to store a reference to them in a SimSet and delete them individually?
Thanks!
Dennis
Thanks!
Dennis
#2
edit:
I obviously just jumped in without checking what you required specifically so here is how you would do it with sprite objects in the scene graph.
02/19/2007 (6:16 am)
Using a SimSet would be the less error prone way to do it but if you simply want to list all objects of a certain type then you could use something like this (this is for datablocks):%dbSet = getT2DDatablockSet();
%cnt = %dbSet.getCount();
for( %i = 0; %i < %cnt; %i++ )
{
%db = %dbSet.getObject( %i );
if( %db.getClassName() $= "t2dImageMapDatablock" )
{
... // Do something with the datablock
}
}edit:
I obviously just jumped in without checking what you required specifically so here is how you would do it with sprite objects in the scene graph.
%cnt = YourSceneGraph.getSceneObjectCount();
for( %i = 0; %i < %cnt; %i++ )
{
%obj = YourSceneGraph.getSceneObject( %i );
if( %obj.getClassName() $= "t2dStaticSprite" ) // change to classes you want
{
... // do something with the object
}
}
#3
I love these forums :)
02/19/2007 (8:25 am)
Sweet, Neo. I always assumed that there would be a way to do that, but never bothered to see how ;)I love these forums :)
#4
@Tom: I thought about using a SimGroup but I'm always iffy about them for some reason. A SimSet "feels" safer. I don't know why. ;)
Thanks for the feedback, guys!
02/19/2007 (1:29 pm)
@Neo: That's a great solution, either for this or many other uses. I've been using a SimSet and that's been working well for just pure deleting but this solution will come in handy when I need to make global changes to a class.@Tom: I thought about using a SimGroup but I'm always iffy about them for some reason. A SimSet "feels" safer. I don't know why. ;)
Thanks for the feedback, guys!
#5
02/21/2007 (8:37 am)
@Neo, I'll make sure your examples wind up in the class docs for t2dBaseDataBlock and t2dSceneGraph, along with attribution.
#6
Glad to help your project too, it really is commendable. Feel free to pick my brain for anything else you might need.
02/21/2007 (8:47 am)
@Arthur:Glad to help your project too, it really is commendable. Feel free to pick my brain for anything else you might need.
#7
02/22/2007 (8:55 pm)
Thanks! Sure thing. (See you over in GoogleGroups.)
Associate Tom Eastman (Eastbeast314)
Hope that helps :)