Page 1 of 1

actor parenting, why doesnt this work?

PostPosted: Mon Mar 28, 2011 10:57 am
by sonicfire
Code: Select all
Actor *myLegL;
myLegL = CreateActor("ratLegL", "ratLegLeft", "(none)", "(none)", 0, 0, false);
ChangeParent("Event Actor", myLegL);


Illegal conversion from struct to const char! Can anybody help me here?
The deal is, when i create my rat actor it should create legs with it and move them also when the rat moves :)

Thanks so much in advance!!

Re: actor parenting, why doesnt this work?

PostPosted: Mon Mar 28, 2011 1:23 pm
by Kodo
Try this instead (a slight tweak to your third line):

Code: Select all
Actor *myLegL;
myLegL = CreateActor("ratLegL", "ratLegLeft", "(none)", "(none)", 0, 0, false);
ChangeParent("Event Actor", myLegL->clonename);

Re: actor parenting, why doesnt this work?

PostPosted: Mon Mar 28, 2011 1:44 pm
by lcl
Yeah, the problem was that ChangeParent(); input values are actors names, not actors themselves. :)

Btw, I didn't know that CreateActor(); returns the created actor, I thought it was void type function.
But thats pretty useful. :)

Re: actor parenting, why doesnt this work?

PostPosted: Mon Mar 28, 2011 4:13 pm
by sonicfire
thanks so much! :)

i thought createactor would return a pointer??

Re: actor parenting, why doesnt this work?

PostPosted: Mon Mar 28, 2011 4:22 pm
by sonicfire
got another little question:

in my actor´s creation event i have "Actor *theleg;" for example.
HOW can i access this pointer in the actor´s draw event?

For example:
Code: Select all
theleg->x = blabla;


The problem is that the variable "theleg" somehow doesn´t exist in the drawevent.
But i cant make it global using code since i need it for any actor seperately.
Hope my post makes sense. Any help / ideas ? :)

Thanks in advance!

Re: actor parenting, why doesnt this work?

PostPosted: Mon Mar 28, 2011 10:16 pm
by skydereign
This can be done in several ways, but before that, your original problem can be solved by this (among others).
Code: Select all
CreateActor("ratLegL", "ratLegLeft", "(none)", "(none)", 0, 0, false);
ChangeParent("Event Actor", ratLegL.clonename);


Reason being while CreateActor returns the created actor (can be very useful by the way), it also sets the default actor actorName to the last created actor. So using ratLegL.clonename will guarantee that it was the actor created in the first line. That might have made less sense than I intended it to.

Anyway, moving on to your other problem, if you declare a variable in a script event, it is a local variable. That is to say, if you declare one in the Create Actor event, it won't exist in the draw. Now, if you possibly can, you want to use creator or parent, but that won't always work. Therefore you will need to use a getclone type function, and store an index. For example, if you want a leg actor, create an actor variable, legIndex.
Code: Select all
legIndex = CreateActor("ratLegL", "ratLegLeft", "(none)", "(none)", 0, 0, false)->cloneindex;
ChangeParent("Event Actor", ratLegL.clonename);


That way you store the cloneindex so you can use a getclone2 function to retrieve the Actor* that you were trying to use in draw.
Code: Select all
Actor* theleg = getCloneIdx("ratLegL", legIndex);
theleg->x= blabla;

Re: actor parenting, why doesnt this work?

PostPosted: Wed Mar 30, 2011 6:54 pm
by sonicfire
amazing! thanks so much! :)