Be careful: when you use something like while (you), "YOU" should be a singleton pointer! If other entities (more parent entities) are assigning to the you pointer, you might get wrong results.

I suggest doing it that way:

  • when the parent creates the child, save directly after ent_create the parent-child association by storing the parent pointer into the child. E.g you = ent_create(...); you.skill10 = my;
  • as replacement for your main loop of the child object, just place a while loop with (1) argument (infinite loop)
  • in the end of the loop before the wait(1); just proof at first if the parent skill is != 0. If it is ==0, the child is a newborn without the parent association. You can circumvent this by waiting one frame before the main loop of your child starts. If it is != 0, a pointer has been stored in it.
  • fill it into an entity pointer: you = my.skill10; Now proof you against NULL to see wether the parent entity is present or not. If it is == NULL, the association exists, but no target in the memory. So, the parent is lost (or removed). If == NULL, you can branch and use break; to leave the loop. If YOU != NULL, the parent entity is available and you can proceed on this.


Thats all. This is a very defensive way, because you store in each child the link to the parent. YOU is a very generic pointer. You should NOT use it in general for constant or global references and associations.

Cheers,
Christian

Last edited by HeelX; 01/31/07 10:36.