actor parenting, why doesnt this work?

Non-platform specific questions.

actor parenting, why doesnt this work?

Postby sonicfire » Mon Mar 28, 2011 10:57 am

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!!
sonicfire
 
Posts: 425
Joined: Wed Nov 01, 2006 9:34 pm
Location: berlin germany
Score: 16 Give a positive score

Re: actor parenting, why doesnt this work?

Postby Kodo » Mon Mar 28, 2011 1:23 pm

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);
Inogames: http://www.inogames.com iOS gaming
Firetop Adventure (app store): http://itunes.apple.com/us/app/firetop- ... ?mt=8&ls=1
User avatar
Kodo
 
Posts: 449
Joined: Thu Oct 20, 2005 8:20 pm
Location: UK
Score: 23 Give a positive score

Re: actor parenting, why doesnt this work?

Postby lcl » Mon Mar 28, 2011 1:44 pm

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. :)
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: actor parenting, why doesnt this work?

Postby sonicfire » Mon Mar 28, 2011 4:13 pm

thanks so much! :)

i thought createactor would return a pointer??
sonicfire
 
Posts: 425
Joined: Wed Nov 01, 2006 9:34 pm
Location: berlin germany
Score: 16 Give a positive score

Re: actor parenting, why doesnt this work?

Postby sonicfire » Mon Mar 28, 2011 4:22 pm

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!
sonicfire
 
Posts: 425
Joined: Wed Nov 01, 2006 9:34 pm
Location: berlin germany
Score: 16 Give a positive score

Re: actor parenting, why doesnt this work?

Postby skydereign » Mon Mar 28, 2011 10:16 pm

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;
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: actor parenting, why doesnt this work?

Postby sonicfire » Wed Mar 30, 2011 6:54 pm

amazing! thanks so much! :)
sonicfire
 
Posts: 425
Joined: Wed Nov 01, 2006 9:34 pm
Location: berlin germany
Score: 16 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest