Page 1 of 1

test getAllActorsInCollision specific actors

PostPosted: Tue Feb 13, 2007 11:55 pm
by pixelpoop
Hello all,
I am trying to move certain actors in a collision and not others.
how would you test the array returned by getAllActorsInCollision for a specific actor? In the demo collisionGroups.ged there are actors c1, c2 and c3. how would could you modify the code to only pick up actors c1 and c2 and their clones? The original script is as follows:
Code: Select all
int n;
Actor *actors;
 
actors =  getAllActorsInCollision("Event Actor", &n);
score.textNumber = n;
if(actors)
{
  int i;
  for(i = 0; i < n; i++)
  {
    ChangeParent(actors[i].clonename, "Event Actor");
  }
}

PostPosted: Wed Feb 14, 2007 12:32 am
by makslane

thanks

PostPosted: Wed Feb 14, 2007 5:57 am
by pixelpoop
that really helped. Having the code explained in the code is invaluable to newbies like me. I know it is time consuming but it would rock if you could do that more, even(especially) when the person you are replying to knows how to code. Lessening the learning curve would make the forum and the product more accessible to a wider range of wannaby game creators.

collision test

PostPosted: Wed Feb 14, 2007 6:05 am
by pixelpoop
I hope this helps new programmers learn this faster then I did.

The code tests if an actor in collision with the event actor is called "c1" and only reacts if it is. to use it just replace the existing code in the collisiongroups demo with this:
Code: Select all
int n;
//makes a variable that is an integer named n
Actor *actors;
//makes an array called actors that holds Actors
 
actors =  getAllActorsInCollision("Event Actor", &n);
//includes all the actors that are touching the "event actor" into an array called actors
//the &n sets the total # of actors into the variable called n


if(actors)
//if the array called actors has info stored in it then do the following
    {
  int i;
//makes a variable called i

     for(i = 0; i < n; i++)
//this loops the next statement until i is equal to the number of actors in the array actors.
  {
   
     if(strcmp(actors[i].name, "c1") == 0)
//strcmp compares the two things(strings) in parenthesis and returns a 1 or a 0.
//the ==0 then compares that returned 1 or 0 to see if it equals 0.
//if it equals 0 then the next line is exacuted if not then the next code is not used
       {
           FollowMouse("Event Actor", NONE_AXIS);
           x=x+50;
           y=y+50;
//this makes the actor(that this code is on) not follow. and then changes its x,y coordinates
              }}
}


PostPosted: Wed Feb 14, 2007 6:19 am
by DilloDude
Rather than checking the colliding actors name you might want to use a variable. That way, you can check on more than one actor easily. It depends on your situation. Try setting something like this: http://game-editor.com/forum/tp-2147-De ... ities.html
That way you can have multiple qualities to check in a single integer.

with traits

PostPosted: Thu Feb 15, 2007 11:50 pm
by pixelpoop
Thanks for the tip DilloDude, and Fuzzy very cool stuff.

Here is the new code. To use it you must define the variable "traits" as an actor integer in GE, not in this code. Just paste this new code over the old in the collision groups demo.
Code: Select all
int n;
Actor *actors;


#define lengthy 2
#define hard 4

int traits;
test.traits= lengthy;

c1.traits=lengthy;
c2.traits=hard;
c3.traits=lengthy | hard;
//this code will only work for the original actor and not it's clones!!!
//to make it work for all clones you must click
//events:[add] -> [on create] -> [action script]
//then type "traits=******;" into the scripts on every actor
 
actors =  getAllActorsInCollision("Event Actor", &n);
score.textNumber = n;
if(actors)
{
  int i;
  for(i = 0; i < n; i++)
  {
    if (actors[i].traits == test.traits){
 
         FollowMouse("Event Actor", NONE_AXIS);
           x=x+50;
           y=y+50;
                                         }
  }
 
}


;;