Adding an entity from within an entity, how aknowledge the "creating" entity in the "created" entity?


(John Andersson) #1

I have an entity called Zach. I then make Zach create another entity called Lewis. How do I reference Zach within Lewis?

There will be plenty of Zachs running around, so I need to refer to one of many of the same entity type.


(Mike Evmm) #2

You could do something like:
@Main.as:

var zach:Zach = FP.create(Zach) as Zach;
add(zach.createLewis());

@Zach.as:

public function createLewis():Lewis{
     var newLewis:Lewis = FP.create(Lewis) as Lewis;
     newLewis.zach = this;
     return newLewis;
}

And have Lewis.as have a public variable zach (or a get/set). Then you can read zach from within Lewis (checking beforehand if it’s non-null).

Also I’m alive!


(Zachary Lewis) #3


(Mike Evmm) #4