Iterating through clones in a for loop

Talk about making games.

Iterating through clones in a for loop

Postby plinydogg » Tue Aug 01, 2006 12:53 am

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.
plinydogg
 
Posts: 104
Joined: Thu Aug 25, 2005 8:34 pm
Score: 0 Give a positive score

Postby makslane » Tue Aug 01, 2006 1:45 am

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;
  }
}
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby plinydogg » Tue Aug 01, 2006 1:13 pm

As always, thanks for your help Makslane!
plinydogg
 
Posts: 104
Joined: Thu Aug 25, 2005 8:34 pm
Score: 0 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron