Moveto closest actor

Talk about making games.

Postby Troodon » Sun Jan 07, 2007 4:28 pm

It says:
Error line 27 Wrong number of arguments for MoveTo
I can't die, I already tried
~on the forums since GE 1.3.3~
User avatar
Troodon
 
Posts: 1539
Joined: Thu Jan 12, 2006 3:29 pm
Location: HELL
Score: 56 Give a positive score

Postby makslane » Sun Jan 07, 2007 4:33 pm

You don't need change the MoveTo line.
What's the code?
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby Troodon » Sun Jan 07, 2007 4:35 pm

Here is the full code:
Code: Select all
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, "tree") == 0) //On tree actors
    {
       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", "");
}
I can't die, I already tried
~on the forums since GE 1.3.3~
User avatar
Troodon
 
Posts: 1539
Joined: Thu Jan 12, 2006 3:29 pm
Location: HELL
Score: 56 Give a positive score

Postby makslane » Sun Jan 07, 2007 4:54 pm

If you are using a version prior the 1.3.6, remove the last argument ("") of the MoveTo function.
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby Troodon » Sun Jan 07, 2007 5:04 pm

I'm still using the 1.3.3 version. :oops:
Now it accepted the code but there is no effect in the game. Is this correct?
Code: Select all
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, "tree") == 0) //On tree actors
    {
       double d = distance(sini.x, sini.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");
}


The SINI actor is suppoesed to move towards the closest Tree actor.
I can't die, I already tried
~on the forums since GE 1.3.3~
User avatar
Troodon
 
Posts: 1539
Joined: Thu Jan 12, 2006 3:29 pm
Location: HELL
Score: 56 Give a positive score

Postby makslane » Sun Jan 07, 2007 10:43 pm

I think is a better idea you download the 1.3.6 version and see the sample working.
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby Troodon » Tue Jan 09, 2007 2:51 pm

I downloaded the 1.3.6 demo and I'll try it some days. Why it's so hmm...dark? :lol:
I couldn't get it work yet, but I'll keep trying with the 1.3.6 and when I succeed, I'll just copy the code.
This is also a good oportunity for me to see the latest tutorials and games! :D
I can't die, I already tried
~on the forums since GE 1.3.3~
User avatar
Troodon
 
Posts: 1539
Joined: Thu Jan 12, 2006 3:29 pm
Location: HELL
Score: 56 Give a positive score

Previous

Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest