Page 1 of 1

parent acting on child

PostPosted: Sat Dec 03, 2011 11:48 am
by Nykos
Hi you all, I have a little question. I have an actor caled enemy that creates another actor like this:
Create actor / script:
Code: Select all
CreateActor("rabbit", "rabbit2_attack_right", "Creator Actor", "(none)", 0, 0, false);


Then I set second actor's creator as his parent.
The thing is, I'd like to change second actor's animation from first one's variables.
something like this:
Code: Select all
switch(state)
{
    case 0:
    angle= direction(x, y, player.x, player.y);
    directional_velocity=2;
    switch(dir)
    {
        case 0:
        ChangeAnimation("rabbit", "rabbit2_walk_left", NO_CHANGE);
        break;
        case 1:
        ChangeAnimation("rabbit", "rabbit2_walk_right", NO_CHANGE);
        break;
    }
}
   

The script works perfectly But, Enemy actors are clones so I replaced the code this way:
Code: Select all
ChangeAnimation("child", "rabbit2_walk_left", NO_CHANGE);

But now it does not work anymore. Does someone know what to do to have one enemy actor act on his own second actor?

Thanks in advance :)

Re: parent acting on child

PostPosted: Sat Dec 03, 2011 8:58 pm
by skydereign
Ok, parent actors do not know about their child counterparts. There are ways of linking them together with a variable, or if there is always a 1 to 1 correspondence (like you have because of the CreateActor in the create event) then you can use the variable/cloneindex to create the child actor's clonename. That, or add the code into the child actor's events. That way you can access the parent's variable using parent.variable.

Re: parent acting on child

PostPosted: Sat Dec 03, 2011 9:53 pm
by Nykos
Thanks for the answer Sky, in fact I just did what you said about putting the code in the child's "draw actor" event and it works almost perfectly. But there is still one problem, If I have two enemy actors (or more than two...), the second actors are all created with the latest enemy coordinates.

The green circled GE icons are the enemy actors, and the rabbits are the second actors which are meant to have the same coordinates as their creators. Do i have to make this "Variable/ cloneindex" you talked about previously to set it right?? Or am I just doing something wrong?

Re: parent acting on child

PostPosted: Sat Dec 03, 2011 9:59 pm
by skydereign
Well, you said you want the rabbit to be parented to the actor that created it. But in your CreateActor function call, you are setting the parent to the enemies creator. That's most likely what is throwing off your xy coordinates. So switch "Creator Actor" to "Event Actor".

Re: parent acting on child

PostPosted: Sat Dec 03, 2011 10:06 pm
by Nykos
THANK YOU SO MUCH, it worked. :) I'm always surprised to see that what could take me half a day to solve, is just one little error just in front of me from the beginning...Thanks again man