Game Development Community

SimSet question....

by Steven Hine · in Torque Game Builder · 12/20/2008 (6:55 pm) · 7 replies

Can an object remove itself from a simSet?

#1
12/21/2008 (5:16 am)
Yes. If the object is deleted, it will notify the SimSet which will remove the object.
#2
12/22/2008 (11:23 am)
Ok. Thanks!
#3
12/22/2008 (8:02 pm)
Ok another question:

Can you access an objects functions through a SimSet? Like this:
($selectionSet is a already created list of selected enemies)

$enemy = $selectionSet.getName();
echo("Pos:" SPC $enemy.getPosition());
#4
12/22/2008 (8:35 pm)
%enemy = selectionSet.getObject(0);
%enemy.getPosition();

Note "0" is the index or location of the enemy object in the simset.

I think you could do this.
echo("Pos:" SPC selectionSet.getObject(0).getPosition());
echo("Pos:" SPC selectionSet.getObject(1).getPosition());
echo("Pos:" SPC selectionSet.getObject(2).getPosition());
....etc
#5
12/22/2008 (8:52 pm)
The full list of SimSet methods can be found in the TGB documentation, though the most handy ones will be:

.add(%myObj);
.getCount();
.getObject(%index);
.isMember(%myObj);
.remove(%myObj);
#6
12/22/2008 (8:57 pm)
While we are on the subject of simsets, this blog helped me out with a few problems that I. I don't know if it will be helpful now, but I am certain it will be helpful in the future.

http://www.garagegames.com/blogs/4517/10949
#7
12/24/2008 (7:42 am)
I solved my problem by giving each object a name when created. By doing this I was able to call each object.

This is from my spawning function:
%clone = %this.object.cloneWithBehaviors();
   %clone.setName(%this.baseName @ %this.realCount);
   %clone.startAI = true;
   %this.SpawnSet.add(%clone);

This is from the PlayerClass attack function:
function PlayerClass::MultipleHit(%this)
{
   %totalSelection = $SelectionSet.getCount();
if(%totalSelection != 0)
{
   for(%i = 0; %i < %totalSelection; %i++)
   {
      %enemy = $SelectionSet.getObject(%i).getName();
      //check for player to be within distance
      if(isPlayerInsight(%enemy.getPosition(), %this.magicRange))
      {
         //load effect
         %explosion = new t2dParticleEffect()
         {
            scenegraph = %this.scenegraph;
         };
         //load effect file and set position
         %explosion.loadEffect("~/data/particles/magicHit.eff");
         %explosion.setEffectLifeMode("KILL", 1);
         %explosion.mount(%enemy);
         //play effect
         %explosion.playEffect();
         //health take away
         %enemy.health -= 100;
         //force enemy attack because of hit(this just increases sight distance)
         %enemy.forceAttack();
      }
   }
  
      %bang = alxPlay(MagicHit_Sound);
}
}