How do you grab a reference to an object in the level?
by Brandon Fogerty · in Torque Game Engine Advanced · 08/22/2009 (2:31 pm) · 7 replies
Hi. I have a tree that I created in my level using the level editor. I gave it the name "tree1". I want to place another object near that tree programtically. I tried iterating through the RootGroup structure using the getName method however that seems to return the tree's datablock name and not its individual name. How can I iterate through the list of objects in the level by its name? Thanks in advance!
#2
08/22/2009 (2:44 pm)
Well because ultimately what I want to do is go into the editor and create a bunch of way points. Then programatically, I want to spawn bay guys at those way points to come attack the player. So that is why I am doing it this way. Does Torque not support this out of the box? Do I need to make some engine changes?
#3
Alternately Instead of iterating through a list of objects by name, a better approach could be to put all way points in a SimGroup and iterate through that group like this:
But that's about the way player spawning works already :)
08/22/2009 (3:03 pm)
What about using SpawnSpheres and modified spawn functions from Stronghold then?Alternately Instead of iterating through a list of objects by name, a better approach could be to put all way points in a SimGroup and iterate through that group like this:
%count = WayPointSimGroup.getCount();
for(%i = 0; %i < %count; %i++)
{
%wayPoint = WayPointSimGroup.getObject(%i);
}But that's about the way player spawning works already :)
#4
08/22/2009 (3:13 pm)
Very true however I guess what I need to know for future reference is how can I get the object's name, not its class type. In the world creator mode, you can assign names to objects. I want to be able to iterate through a "WayPointSimGroup" and find out what each way point's name is. How can I do this? By the way, thanks for your responses Stefan.
#5
08/22/2009 (3:24 pm)
There's just one more line needed to get the name you assigned in the editor:%count = WayPointSimGroup.getCount();
for(%i = 0; %i < %count; %i++)
{
%wayPoint = WayPointSimGroup.getObject(%i);
%wayPointName = %wayPoint.getName();
}
#6
08/22/2009 (3:30 pm)
Ok so why don't I see my object's name, "Tree1", when I iterate through the RootGroup structure?
#7
08/22/2009 (4:42 pm)
I think you want to iterate through MissionGroup and not RootGroup :)
Torque Owner Shaderman