I’m trying to build a wrapper that strengthens and fleshes out the component and object oriented aspects of codea for personal use. I can’t seem to find an efficient way to keep track of entities? is there one already implemented? Thanks!
I thought scene:get(type) would work, but I can’t seem to find entities in the scene that way.
@arismoko Right now there’s entity.children
which will return a table of all child entities of a given entity. There isn’t a way to get all root entities, although I could add it (i.e. scene.entities or something)
I could backport some new features from Codea 4 (next major engine rebuild) which would be entity:childAt(index)
and entity.childCount
to make iteration easier
using an iterator would be messy if you remove/insert entities during runtime, better to have something like :childById(name)
@skar Calling entity:destroy()
doesn’t remove the entity until the next scene update (for this exact reason). There is a findChild(name)
method that I could add as well
Thanks for taking the time to respond! I’ve been trying to implement my own findChild(name) function all day, but I’m having some problems. When I retrieve the table that contains a parent’s children all the names that have been set for them are set to nil. No matter what I try.
It would certainly be a huge help if you did implement such a function, I’m a few steps off from having unity in my pocket, and I never thought I’d see the day (:
Is there a reason not to just keep a table of all created entities yourself?
@arismoko I’ll have to add a native name attribute to entities. The reason your names are disappearing is because our lua bindings can dynamically add fields to object instances (like entity) but if the API creates a new copy of the entity from C++ (say entity.children) the copies wont have the custom fields added.
I’ve solved this in Codea 4 with our new binding system but Codea 3.x doesn’t have this right now.
Thank you for the help!