Page 1 of 1

Iterating through clones in a for loop

PostPosted: Tue Aug 01, 2006 12:53 am
by plinydogg
Hi everyone,

I'm trying to calculate the distance between an actor and some clones of another actor, but I can't figure out how to do it properly.

Here's what I'm trying to do, roughly:

int i;
for (i = 0; i < 30; i++)
{
Actor* testActor = someActor.i;
if distance(x, y, testActor->x, testActor->y) //this is the problem, I think
{
//Do some stuff;
}
}

Any ideas?

Any help is much appreciated.

PostPosted: Tue Aug 01, 2006 1:45 am
by makslane
Put the getclone2 function in your global code (http://game-editor.com/forum/viewtopic.php?t=711) and try this:

Code: Select all
int i;
for (i = 0; i < 30; i++)
{
  Actor* testActor = getclone2("someActor", i);

  if(testActor->cloneindex != -1 //Is the actor valid?
   && 
  distance(x, y, testActor->x, testActor->y) < somevalue) )
  {
      //Do some stuff;
  }
}

PostPosted: Tue Aug 01, 2006 1:13 pm
by plinydogg
As always, thanks for your help Makslane!