Page 1 of 1

Actor array problem

PostPosted: Sun Jun 04, 2006 5:31 pm
by Novice
Im trying to assign actors to an actor array, but the problem is that they are created by a shorter version of Create Actor function wich i made. It goes something like this:
Code: Select all
void createEnemy(int i, int x1, int y1)
{
    switch(i)
    {
    case(1):
    CreateActor("a", "anim1", "no parent", "no path", x1, y1, true);
    break;
    case(2):
    CreateActor("a2", "anim1", "no parent", "no path", x1, y1, true);
    break;
    case(3):
    CreateActor("a3", "anim1", "no parent", "no path", x1, y1, true);
    break;
    }
}

It creates an actor by number insetad of name. Now in another function im trying to asign actors created by this function to an array. The other function goes like this:
Code: Select all
Actor *enemy[4];
void placeEnem(int en1, int en2, int en3, int en4)
{
if (en1!=0&&en2!=0&&en3!=0&&en4!=0)
{
    enemy[1]=createEnemy(en1,view.x+40, view.y+50);
    enemy[2]=createEnemy(en2,view.x+90, view.y+50);
    enemy[3]=createEnemy(en3,view.x+150, view.y+50);
    enemy[4]=createEnemy(en4,view.x+200, view.y+50);
}

When i try to add this i get a message "cannont convert from 'void' to '* struct' "
I we tried to do it with this
Code: Select all
enemy[1]=CreateActor("a", "anim1", "no parent", "no path", view.x+90, view.y+50, true);

and it works perfectly! But i need to use the CreateEnemy function, so i can't do it that way.

I think that i need to redefine one of my functions but to what i don't know.
What am i doing wrong? I'we been busting my head about this for hours, someone please help :cry:
TIA

PostPosted: Sun Jun 04, 2006 7:10 pm
by plinydogg
Novice,

I think I almost understand what you're trying to do, but can you try to explain exactly what you want to do (not in code, but in normal parlance or pseudocode)?

PostPosted: Sun Jun 04, 2006 9:19 pm
by makslane
Your function must return a pointer to an Actor struct:

Code: Select all
Actor *createEnemy(int i, int x1, int y1)
{
    Actor *act = NULL;
    switch(i)
    {
    case 1:
    act = CreateActor("a", "anim1", "no parent", "no path", x1, y1, true);
    break;
    case 2:
    act = CreateActor("a2", "anim1", "no parent", "no path", x1, y1, true);
    break;
    case 3:
    act = CreateActor("a3", "anim1", "no parent", "no path", x1, y1, true);
    break;
    }

    return act;
}

PostPosted: Mon Jun 05, 2006 4:01 pm
by Novice
Thaks :D , il try it out as soon as i can!

PostPosted: Mon Jun 05, 2006 10:26 pm
by Novice
Thanks, it works perfectly!!! :mrgreen: :mrgreen: :mrgreen:

PostPosted: Tue Jun 06, 2006 5:51 pm
by Novice
Ok, everything works fine now but if i play in game mode long enough, and return to editor mode some actors are gone!!! They are not eaven in the actor list! Does this have something to do with my functions or is it a bug?

PostPosted: Tue Jun 06, 2006 11:50 pm
by makslane
Send me the game with instructions to reproduce the problem.
I will see what's happen.

PostPosted: Wed Jun 07, 2006 9:52 am
by Novice
I sent it.

PostPosted: Thu Jun 08, 2006 5:36 pm
by makslane
Ok, I will see and reply you soon.