Control all objects of a class...
by Austin Reynolds · in Torque Game Builder · 09/29/2008 (5:10 pm) · 7 replies
This is probably a stupid question and I know I seen the answer just a while ago but now cannot find it. So anyways ->
Lets say I have a class named "circles". I have 10 objects on the screen(all circles :) )
After 1 of them is clicked I want them all to disappear. Im not worried on how to make them disappear or be deleted but how to loop thru all of the objects that are under the class "circles" and run a function like ->
function circles::onMouseDown(%this)
{
%this.setAngularVelocity(10);
}
any help would be awesome!
Lets say I have a class named "circles". I have 10 objects on the screen(all circles :) )
After 1 of them is clicked I want them all to disappear. Im not worried on how to make them disappear or be deleted but how to loop thru all of the objects that are under the class "circles" and run a function like ->
function circles::onMouseDown(%this)
{
%this.setAngularVelocity(10);
}
any help would be awesome!
About the author
#2
09/29/2008 (7:40 pm)
Thank you very much I believe this is exactly what I was looking for. I knew it would/was simple.
#3
if (!isObject(circlesSet))
{
new ScriptGroup(circlesSet);
echo("circlesSet created...");
}
circlesSet.add(%this);
echo("added");
so that I could see how many times it went thru and added. Everything seems to go well. I adds 4 times which is correct and it creates the circlesSet before it adds so that's correct. It only creates it 1 time which is also correct.
The problem im running into is when I run the applyToCircles it doesn't do anything. So in counsel I ran this
echo(circlesSet.getCount());
it echoed out 0 for some reason its not showing theres anything in there but when it adds it thinks there is otherwise it wouldnt be adding with out creating a new set right?
Im going to try a few things but just thought I would throw this out there before I head off for the night.
09/29/2008 (8:03 pm)
I changed the onAdd to thisif (!isObject(circlesSet))
{
new ScriptGroup(circlesSet);
echo("circlesSet created...");
}
circlesSet.add(%this);
echo("added");
so that I could see how many times it went thru and added. Everything seems to go well. I adds 4 times which is correct and it creates the circlesSet before it adds so that's correct. It only creates it 1 time which is also correct.
The problem im running into is when I run the applyToCircles it doesn't do anything. So in counsel I ran this
echo(circlesSet.getCount());
it echoed out 0 for some reason its not showing theres anything in there but when it adds it thinks there is otherwise it wouldnt be adding with out creating a new set right?
Im going to try a few things but just thought I would throw this out there before I head off for the night.
#4
09/29/2008 (8:38 pm)
Make sure you have the %this parameter in your onAdd function. As one possiblity.
#5
09/29/2008 (8:43 pm)
You probably do want to keep track of them in a simset, but an alternative, just for future knowledge, is to get a list of all t2dSceneObject's from the SceneGraph ( t2dSceneGraph::getSceneObjectList() ) then loop through them checking for the classname.
#6
09/30/2008 (7:41 am)
Ok ill try messing around with that. This is just a small script im messing around with so I can change it to whatever we/I need.
#7
"new ScriptGroup(circlesSet);"
to
"new SimSet(circlesSet);"
Fixed the problem. Thanks alot!
09/30/2008 (8:17 am)
Just changing "new ScriptGroup(circlesSet);"
to
"new SimSet(circlesSet);"
Fixed the problem. Thanks alot!
Associate Phillip O'Shea
Violent Tulip
function circles::onAdd(%this) { if (!isObject(circlesSet)) new ScriptGroup(circlesSet); circlesSet.add(%this); } // Example: // applyToCircles("setLinearVelocity(10);"); function applyToCircles(%functionCall) { %circlesCount = circlesSet.getCount(); for (%i = 0; %i < %circleCount; %i++) eval (circlesSet.getObject(%i) @ "." @ %functionCall); }Something like that will do ;)