Game Development Community

Iterating over all sceneobjects in a behavior

by Joe Spataro · in Torque Game Builder · 04/16/2007 (6:47 pm) · 3 replies

What is the script to iterate over all scene objects from within a behavior?

i imagine its something like

for ( %i = 0; %i < %this.owner.scenegraph.getSceneObjectCount(); %i++ )
{
    // is there a way to get sceneObject %i ??
    // %this.owner.scenegraph.getSceneObject() doesn't take an index
    // what to do?
}

thanks,
joe.s

#1
04/17/2007 (5:48 am)
A scene graph is impleneted through a SimGroup(or Set.. I am not sure right now, and can't check from this comp.. someone correct me if I am wrong). So you can use the same methods(getObjectCount and getObject(index). When in doubt, start the engine, open the console, create a SimGroup($a = new SimGroup();) and call $a.dump().
#2
04/17/2007 (9:33 am)
Actually, t2dSceneGraph::getSceneObject() does take an index. There is probably just a misprint in the documentation.
#3
04/30/2007 (3:23 pm)
for(%i = 0; %i < $YourVariable.getCount(); %i++) //to get count
   {
      %yourObject = $YourVariable.getObject(%i); //to get object
      if(%yourObject.isOnline $= true)
      {
         %yourObject.yourFunction();
      }
   }

$YourVariable Should be a Sim Set();

I hope this sample helps you out :)