Game Development Community

how can I dynamicaly get a list of all instances of a certain object (decal road)

by David Stoesz · in Torque 3D Professional · 12/22/2009 (12:11 am) · 3 replies


Here is what I am looking at doing. I want to use the decal roads in my game as a basic path for my AI's to find their way arround following the roads. In my code, I need to get a list of all the roads so that I can find things like (which road am I closest to) and tap into helper functions that I will write in the decal road code.
Is there a way that I can (in script or code) generate that list in a reasonably efficient way? or should I just create a datablock that stores this information?

Also if this is a really bad way to do this, please say so.

Oh, using 1.1Alpha right now.

#1
12/22/2009 (10:34 am)
You could put all of your decal roads in a SimGroup named "DecalRoads". This would allow you to get to them either through code or script without having to search and "generate a list" since they'd already be organized together.

In C++:

SimGroup *decalRoads;
Sim::findObject("DecalRoads", decalRoads);

for(SimGroup::iterator itr = decalRoads->begin(); itr != decalRoads->end(); itr++)
{
   DecalRoad *pRoad = static_cast<DecalRoad*>(*itr);

   // Do something with the road...
}

In script:

for(%i = 0; %i < DecalRoads.getCount(); %i++)
{
   %road = DecalRoad.getObject(%i);

   // Do something with the road...
}
#2
12/22/2009 (12:59 pm)
Thank you Ryan, that was exactly what I was looking for. I thought there must be a way to do this fairly simply.

Thanks again.
#3
12/28/2009 (4:29 pm)
Depending on how accurate you need this to be and how curvy your roads are, you might need to implement a better distanceTo method for DecalRoad ( it is a virtual in SceneObject ).

And if you do this from script you will also need to expose that as a ConsoleMethod ( unless you are measuring distance some other way ).