Actor array problem

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

Actor array problem

Postby Novice » Sun Jun 04, 2006 5:31 pm

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
Why do i always get stuck?
User avatar
Novice
 
Posts: 399
Joined: Mon Aug 29, 2005 10:54 am
Location: Relative
Score: 5 Give a positive score

Postby plinydogg » Sun Jun 04, 2006 7:10 pm

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)?
plinydogg
 
Posts: 104
Joined: Thu Aug 25, 2005 8:34 pm
Score: 0 Give a positive score

Postby makslane » Sun Jun 04, 2006 9:19 pm

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;
}
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby Novice » Mon Jun 05, 2006 4:01 pm

Thaks :D , il try it out as soon as i can!
Why do i always get stuck?
User avatar
Novice
 
Posts: 399
Joined: Mon Aug 29, 2005 10:54 am
Location: Relative
Score: 5 Give a positive score

Postby Novice » Mon Jun 05, 2006 10:26 pm

Thanks, it works perfectly!!! :mrgreen: :mrgreen: :mrgreen:
Why do i always get stuck?
User avatar
Novice
 
Posts: 399
Joined: Mon Aug 29, 2005 10:54 am
Location: Relative
Score: 5 Give a positive score

Postby Novice » Tue Jun 06, 2006 5:51 pm

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?
Why do i always get stuck?
User avatar
Novice
 
Posts: 399
Joined: Mon Aug 29, 2005 10:54 am
Location: Relative
Score: 5 Give a positive score

Postby makslane » Tue Jun 06, 2006 11:50 pm

Send me the game with instructions to reproduce the problem.
I will see what's happen.
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby Novice » Wed Jun 07, 2006 9:52 am

I sent it.
Why do i always get stuck?
User avatar
Novice
 
Posts: 399
Joined: Mon Aug 29, 2005 10:54 am
Location: Relative
Score: 5 Give a positive score

Postby makslane » Thu Jun 08, 2006 5:36 pm

Ok, I will see and reply you soon.
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest