test getAllActorsInCollision specific actors

You must understand the Game Editor concepts, before post here.

test getAllActorsInCollision specific actors

Postby pixelpoop » Tue Feb 13, 2007 11:55 pm

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");
  }
}
User avatar
pixelpoop
 
Posts: 276
Joined: Tue Aug 29, 2006 9:32 pm
Score: 28 Give a positive score

Postby makslane » Wed Feb 14, 2007 12:32 am

makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

thanks

Postby pixelpoop » Wed Feb 14, 2007 5:57 am

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.
User avatar
pixelpoop
 
Posts: 276
Joined: Tue Aug 29, 2006 9:32 pm
Score: 28 Give a positive score

collision test

Postby pixelpoop » Wed Feb 14, 2007 6:05 am

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
              }}
}

User avatar
pixelpoop
 
Posts: 276
Joined: Tue Aug 29, 2006 9:32 pm
Score: 28 Give a positive score

Postby DilloDude » Wed Feb 14, 2007 6:19 am

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.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

with traits

Postby pixelpoop » Thu Feb 15, 2007 11:50 pm

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;
                                         }
  }
 
}


;;
User avatar
pixelpoop
 
Posts: 276
Joined: Tue Aug 29, 2006 9:32 pm
Score: 28 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest