passing pointer to action/function?

Posted By: wrekWIRED

passing pointer to action/function? - 11/04/13 16:05

I'm making an entity with multiple body parts. Basically the parent body creates it's child part.

something like this.
Code:
action body_action()
action child_action()

ENTITY* body = ent_create(body, pos, body_action);

//main body action
action body_action()
{
   //msc codes here
   code...

   //create child entity
   ent_create(part1, pos_parentoffset, child_action(me)); //point me as parent entity

   //rest of the child entity code
   code...
}

//child body action
action child_action(ENTITY* parent_ent)
{
   //msc codes here
   code...

   while(1)
   {
       //parent_ent pointing to main body
       vec_set(my.x, parent_ent.x);
       wait(1);
   }
}



now the code just throws undeclared identifier for parent_ent. Reason for each body processing it's child part it because I'm spawning multiple entities of the same type each creating it's own parts and each part updates base on it's own parent entity.

What am I doing wrong it this case?
Posted By: Anonymous

Re: passing pointer to action/function? - 11/04/13 16:15

You can not pass arguments in that way But YOU is always pass as the creator to the created action.

me-> create
created -> parent always is YOU in first run



Code:
//main body action
action body_action()
{
   //msc codes here
   code...

   //create child entity
   ent_create(part1, pos_parentoffset, child_action); //point me as parent entity

   //rest of the child entity code
   code...
}

//child body action
action child_action()
{
   //msc codes here
   code...
   ENTITY* parent_ENT = you;

   while(1)
   {
       //parent_ent pointing to main body
       vec_set(my.x, parent_ent.x);
       wait(1);
   }
}



EDIT___
Posted By: wrekWIRED

Re: passing pointer to action/function? - 11/04/13 16:25

I see. My child action actually have multiple var parameters aside for the main body pointer it self. How do I pass parameters to each child actually call?
Posted By: Ch40zzC0d3r

Re: passing pointer to action/function? - 11/04/13 16:43

Just set the arguments with skills (you have to wait 1 frame until they were set in the child function)
Eaisiest way indeed.
Posted By: wrekWIRED

Re: passing pointer to action/function? - 11/04/13 16:56

I was hoping to save skills for other purpose. But I don't think I can use them all anyway.

Thanks guys.
© 2024 lite-C Forums