get clone object number from `movetoclosestactor` routine

Game Editor comments and discussion.

get clone object number from `movetoclosestactor` routine

Postby akhad » Thu Jun 14, 2007 7:10 pm

I've found the movetoclosestactor code very handy (code follows) but I'd like to get the closest clones object number too. How can I extract the actual number of (closest->clonename) ready for display in a text.number ?

movetoclosestactor code:

int n;
double mindist = 10000; //Initialize min distance with some high value
Actor *actors, *closest = NULL;

//Get all actors that collides with the sensor actor
actors = getAllActorsInCollision("Event Actor", &n);


if(actors)
{
int i;
for(i = 0; i < n; i++)
{
if(strcmp(actors[i].name, "player") != 0) //Ignore the player actor
{
double d = distance(player.x, player.y, actors[i].x, actors[i].y);
if(d < mindist)
{
//Hold the closest actor
closest = (actors + i);
mindist = d;
}
}
}
}

//Move the closest actor, if any
if(closest)
{
MoveTo(closest->clonename, 0, 0, 5, "player", "");
}
User avatar
akhad
 
Posts: 43
Joined: Tue Jan 16, 2007 1:59 pm
Location: U.K
Score: 0 Give a positive score

Postby makslane » Thu Jun 14, 2007 9:13 pm

You can use:

Code: Select all
textNumber = closest->cloneindex;
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby akhad » Thu Jun 14, 2007 9:36 pm

Yes, that makes sense now I see it. I've only just really started looking into clone actors and the power is impressive. I'd really like to see more tutorials on this, it's the key to potentially very professional game structures.
Thanks.
User avatar
akhad
 
Posts: 43
Joined: Tue Jan 16, 2007 1:59 pm
Location: U.K
Score: 0 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron