How to iterate child objects

[lua]for object in map.layer[“objects”].objects()[/lua]

Seems only iterate the host objects. I need to iterate all built child objects for pausing the game. First I was thinking to make host object pause and resume function for the child object, but then I remembered you saying not to modify host objects. 

I’m pretty sure those are display groups.

https://docs.coronalabs.com/daily/api/type/GroupObject/index.html

local group = display.newGroup() display.newCircle( group, 10, 10, 10 ) print( "Group contains: ", group.numChildren ) -- "Group contains: 1" display.newCircle( group, 10, 10, 10 ) print( "Group contains: ", group.numChildren ) -- "Group contains: 2" display.newCircle( group, 10, 10, 10 ) print( "Group contains: ", group.numChildren ) -- "Group contains: 3" for i = 1, group.numChildren do -- something here end

Feel free to modify the host objects, just don’t delete them or move them into another group.

What I do is add a “hostObject” and “builtObject” property to the objects I build and the host objects, then I can access either object when I have access to one of them. So to iterate through each built object, you’d just do a for object in map.layer[“layer”].objects() do and access the object.builtObject.

  • Caleb

I’m pretty sure those are display groups.

https://docs.coronalabs.com/daily/api/type/GroupObject/index.html

local group = display.newGroup() display.newCircle( group, 10, 10, 10 ) print( "Group contains: ", group.numChildren ) -- "Group contains: 1" display.newCircle( group, 10, 10, 10 ) print( "Group contains: ", group.numChildren ) -- "Group contains: 2" display.newCircle( group, 10, 10, 10 ) print( "Group contains: ", group.numChildren ) -- "Group contains: 3" for i = 1, group.numChildren do -- something here end

Feel free to modify the host objects, just don’t delete them or move them into another group.

What I do is add a “hostObject” and “builtObject” property to the objects I build and the host objects, then I can access either object when I have access to one of them. So to iterate through each built object, you’d just do a for object in map.layer[“layer”].objects() do and access the object.builtObject.

  • Caleb