How to get parent table from element?

In my game, I am adding one display object as child of another as below

1
2
local art = sprite.newSprite(artSet)  --This being main display object 
art.sensor = display.newCircle(art.x,art.y,100)  -- This being attached object which is a sensor object to implement "attack" range for art object.

In your creation for the art.sensor object you haven't passed in a displayGroup which means it gets added to the current stage.

1
2
3
-- Adds to the global stage
 
local sensor = display.newCircle( art.x, art.y, 100 )

To add to the above now you have sensor added to the group you can reference to it as group.sensor or you can simplify to group.sensor = sensor and just use sensor again :)

No, that's not what I want.

I know how to use display groups.

What I am doing is just adding one display object as property of another. Or in LUA terms, making one table as a element of another. (as display objects are just tables in reality)

Setting "art.sensor" as a display object is yes, as you say, adding the object as a property of the other however it does not make "art" the parent of "sensor". Is this what you are trying to do?

-- edit -

Or are you trying to find a more generic Lua way of finding the parent table regardless of Corona etc? If so, might get a better response in the Lua Language subforum - http://developer.anscamobile.com/forum/11

Thanks.. I ended up asking ppl in IRC #lua channel..

I was indeed trying to find a more generic Lua way of finding the parent table regardless of Corona.

According to ppl there, I have to store reference to parent within the child to get handle back to parent.

Ah right yea that would do it, shame there isn't a more inbuilt way but that is easy enough.

views:1561 update:2011/9/29 19:21:19
corona forums © 2003-2011