Accessing the properties of a display group child.

So first, hello! Second; been working with corona for some time now and finally ran into a problem I havent been able to solve myself. I feel like the solution is right in front of me but a clear answer isn’t presenting itself in the (generally) great documentation. I also couldn’t find anything in the forum and do apologize if i missed it. Here we go:

I am creating a top down grid based game(simply put). I have taken care of spawning in a grid of display objects using a nested loop in a function.

During this loop i insert “grid[i][j]” into a display group that is returned at the end of the function. This is done after all the properties of the display object that resides in “grid[i][j]” have been set.

This group is assigned to “currentLevel”. 

so my question is this: how can I access the properties of a child within my “currentLevel” display group. Specifically the x and y coordinates.

I assumed something like currentLevel[grid][3][4].x would work but it hasn’t thus far and everything else i try says the same “attempted to index a nil value” which it isn’t because i created a debug function earlier so that i could click on a item and see its’ name and grid position.

should i just return the table of display objects as well as the group. I need them to be in a group so the placement of the entire level stays on the x center.

The display.group isn’t going to keep any references to your grid’s i, J’s.  Why not make grid a local at the top of your code (an upvalue) and just reference things as grid[][] like you want.  Use the group for group wide things.

Rob

Thanks for clarifying. That’s what I ended up doing essentially.

The display.group isn’t going to keep any references to your grid’s i, J’s.  Why not make grid a local at the top of your code (an upvalue) and just reference things as grid[][] like you want.  Use the group for group wide things.

Rob

Thanks for clarifying. That’s what I ended up doing essentially.