Adding Actors to an Array

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

Adding Actors to an Array

Postby jazz_e_bob » Sun Apr 08, 2007 10:42 am

I want to make my own array of actors.

Please consider the following code:

Code: Select all
int n;  // actor count

Actor *allActors;
Actor *happyActors;

allActors = getAllActorsInCollision("gameArea.0", &n);

if(allActors)
{
    int i;
    for( i = 0; i < n; i++ )
    {
        if ( allActors[i].myMood == HAPPY )
        {
            // add to happy actor array
            // ???????????????????????? 
        }
    }
}


How do I add the happy actors to my array?
Controlling complexity is the essence of computer programming.
User avatar
jazz_e_bob
 
Posts: 742
Joined: Tue Jul 01, 2003 9:38 pm
Location: Bloke from Cockatoo Creek Australia
Score: 14 Give a positive score

Postby makslane » Sun Apr 08, 2007 12:54 pm

Will need allocate an array of actor pointers:
Code: Select all
Actor *happyActors[32]; //for 32 actors max


And to add:
Code: Select all
happyActors[n] = allActors+i;


So, your code will look something like this:

Code: Select all
int n, nh = 0;

Actor *allActors;
Actor *happyActors[32]; //for 32 actors max


allActors = getAllActorsInCollision("gameArea.0", &n);

if(allActors)
{
    int i;
    for( i = 0; i < n; i++ )
    {
        if ( allActors[i].x == 0 )
        {
            // add to happy actor array
            happyActors[nh++] = allActors+i;           
        }
    }
}


//For access the data, use the operator ->
Code: Select all
happyActors[0]->x = 0;
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby jazz_e_bob » Sun Apr 08, 2007 9:15 pm

Thanks mate!

:)
Controlling complexity is the essence of computer programming.
User avatar
jazz_e_bob
 
Posts: 742
Joined: Tue Jul 01, 2003 9:38 pm
Location: Bloke from Cockatoo Creek Australia
Score: 14 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest