Game Development Community

How do I manage a levels state in TGB?

by Storm Kiernan · in Torque Game Builder · 05/10/2011 (4:50 pm) · 2 replies

For instance, I want to maintain a list of all of my enemies so that I can search for the closest one to the player. This is just one case, but there are others. I just don't know the place where this should be done.

#1
05/10/2011 (5:09 pm)
In your onAdd method of the enemy class, you can add your enemy to a simGroup. Something like

function EnemyClass::onAdd(%this)
{
   if(!isObject($EnemyGroup))
   {
       $EnemyGroup = new SimGroup(){};
   }
   $EnemyGroup.add(%this);
}

Most of the events in the Engine have callbacks to script, so you'll have to know what you need and design your code to do what you want with those events.
#2
05/10/2011 (10:30 pm)
That bit of code looks good to me. Designing around the event-driven engine will be the real task at this point. Any suggestions?