safeDeleteGroup()?
by rennie moffat · in Torque Game Builder · 12/21/2010 (9:30 pm) · 11 replies
Is there a way to safeDeleteGroup()?
About the author
My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.
#2
By the way, merry Christmas Patrick, it is Roller jesus' birthday too no?
Anyhow...if I create objects 1 thru 7, set them to all be part of group 9. What advantages does this yield?
12/28/2010 (4:31 pm)
So I am wondering, By the way, merry Christmas Patrick, it is Roller jesus' birthday too no?
Anyhow...if I create objects 1 thru 7, set them to all be part of group 9. What advantages does this yield?
#3
Generally you would use that group (assuming you mean Graph Group - the one you set in the editor) as a mask when executing a pickPoint or pickRect to include/exclude items from the result set.
However you could do something like this to loop through and safeDelete items in a certain group:
12/28/2010 (5:51 pm)
Sweet baby RollerJesus!Generally you would use that group (assuming you mean Graph Group - the one you set in the editor) as a mask when executing a pickPoint or pickRect to include/exclude items from the result set.
However you could do something like this to loop through and safeDelete items in a certain group:
//this needs to be in a valid onLevelLoaded function
$SG = %this.getSceneGraph();
//Called to clear when you need
clearGroup(2); //clear all objects in group 2
function clearGroup(%groupNum)
{
for(%i = 0; %i < $SG.getCount(); %i++)
{
%currentObject = $SG.getObject(%i);
if(%currentObject.getGraphGroup() == %groupNum)
{
%currentObject.safeDelete();
}
}
}
#4
so this bit of code you provided I have a few questions....
1. by using "getCount", it counts however many objects are in group 2?
2. this function simply runs through all objects in group 2 and deletes them?
3. and this is a prime example of the purpose of groups? Are there any other examples of groups? Say, creation..... cant think of anything else.
And thanks!
12/28/2010 (8:50 pm)
Thanks RollerJesus, Everyone loves Baby RollerJesus!so this bit of code you provided I have a few questions....
1. by using "getCount", it counts however many objects are in group 2?
2. this function simply runs through all objects in group 2 and deletes them?
3. and this is a prime example of the purpose of groups? Are there any other examples of groups? Say, creation..... cant think of anything else.
And thanks!
#5
To answer your questions:
1) Using getCount in this context get the number of all objects in the scenegraph (or all objects in your game). This can be slow, so use it with caution. This is not the *best* way to do this, but rather an answer to your initial question if you *could* do this.
2) No, this function runs through all objects in the scenegraph, checks if it's in group 2 then deletes them if they are
3) This is a poor example of groups. A much better way to do this would be to add the objects to a SimSet or SimGroup when you create them (in script). Then you can modify/delete/etc as you wish on each SimSet.
12/28/2010 (9:20 pm)
Hey Rennie, I'm just going to comment the code better in hopes that it clarifies it for you...//this needs to be in a valid onLevelLoaded function
//it stores the scenegraph in a global variable for access later
$SG = %this.getSceneGraph();
//this is how to hook into clearing all items in a group
//Example: clear all objects in group "2"
clearGroup(2);
//this loops through ALL object in the scenegraph and deletes
//those in %groupNum (in this case, 2)
function clearGroup(%groupNum)
{
//loop through all objects in the scenegragh
for(%i = 0; %i < $SG.getCount(); %i++)
{
//store a local var of each item as we loop through
%currentObject = $SG.getObject(%i);
//check if that object is in group 2...
if(%currentObject.getGraphGroup() == %groupNum)
{
//...safe delete it if it's in group 2
%currentObject.safeDelete();
}
}
}To answer your questions:
1) Using getCount in this context get the number of all objects in the scenegraph (or all objects in your game). This can be slow, so use it with caution. This is not the *best* way to do this, but rather an answer to your initial question if you *could* do this.
2) No, this function runs through all objects in the scenegraph, checks if it's in group 2 then deletes them if they are
3) This is a poor example of groups. A much better way to do this would be to add the objects to a SimSet or SimGroup when you create them (in script). Then you can modify/delete/etc as you wish on each SimSet.
#6
12/28/2010 (9:24 pm)
Ok, sorry to ask, but could you give me an example of creating a SimSet or SimGroup?
#7
I jut found this thread which seems useful.
www.torquepowered.com/community/forums/viewthread/42803
in it, he creates an object. With in that creation function he adds....
Is that about it? In how to add an object to a simSet and, in turn, manipulate it?
12/29/2010 (12:47 am)
Hi, I jut found this thread which seems useful.
www.torquepowered.com/community/forums/viewthread/42803
in it, he creates an object. With in that creation function he adds....
enemySet.add(%enemy);and says that, this ads this object to the simSet ("enemySet"). Also that any future call to this object can be used by this....
%obj = enemySet.getObject(0);
Is that about it? In how to add an object to a simSet and, in turn, manipulate it?
#8
12/29/2010 (4:01 am)
I couldn't explain it better than Philip did in that thread.
#10
I am strugling with this a bit as to how to make it best work for my circumstances.
I have created a new object tB0.
now I used your example, thinking that is I set the call to group 4, it would clear tB0. So far no luck and %groupNum is returning 1199. Strange. Not sure what to make of it. How best can I delete all objects in group 4? Sorry if this is stupid. thanks.
01/05/2011 (7:29 pm)
Hi, I am strugling with this a bit as to how to make it best work for my circumstances.
I have created a new object tB0.
%this.tB0 = new t2dSceneObject(tB0)
{
///blah blah blah, size position, scenegraph etc
///this is the important part for this.
group = 4;
}now I used your example, thinking that is I set the call to group 4, it would clear tB0. So far no luck and %groupNum is returning 1199. Strange. Not sure what to make of it. How best can I delete all objects in group 4? Sorry if this is stupid. thanks.
function stage1ManagerBehavior::this(%this)
{
%this.clearGroup(4);
}
//this loops through ALL object in the scenegraph and deletes
//those in %groupNum (in this case, 2)
function stage1ManagerBehavior::clearGroup(%groupNum)
{
echo("clearGroup");
echo("%groupNum" @ %groupNum);
//loop through all objects in the scenegragh
for(%i = 0; %i < $SG.getCount(); %i++)
{
//store a local var of each item as we loop through
%currentObject = $SG.getObject(%i);
//check if that object is in group 2...
if(%currentObject.getGraphGroup() == %groupNum)
{
//...safe delete it if it's in group 2
%currentObject.safeDelete();
}
}
}
Torque Owner RollerJesus
Dream. Build. Repeat.
Loops are your friend here...