How do you ref a group inside a group?

so from a flash background I use groups like movieclips…
I tried this…

local function test(group)  
 print("test1 ",group.childgroup);  
end  
local maingroup = display.newGroup();  
local childgroup = display.newGroup();  
maingroup:insert(childgroup);  
test(maingroup);  

but that prints a null value.

The only way I could do it was first insert the childgroup and then add it as a variable to maingroup

local function test(group)  
 print("test1 ",group.childgroup);  
 print("test2 ",group.child);  
end  
local maingroup = display.newGroup();  
local childgroup = display.newGroup();  
maingroup.child = childgroup;  
maingroup:insert(childgroup);  
test(maingroup);  

so test1 print still prints nil.
but test2 prints out the table and I can use that.

Is that the only way to ref it? [import]uid: 102413 topic_id: 26558 reply_id: 326558[/import]

maingroup[1] will reference “childgroup” [import]uid: 54030 topic_id: 26558 reply_id: 107715[/import]

You could put the groups in a list and reference them like that.

[lua]GroupLists = {}
GroupLists[1] = Group1
GroupLists[2] = Group2
GroupLists[3] = Group3
GroupLists[4] = Group4[/lua]

Then reference/find them like this:

[lua]for p=1, #GroupLists, 1 do
if GroupLists[p].numChildren > 3 then
for i=GroupList[p].numChildren,1,-1 do
local child = GroupList[p][i]

child:setFillColor(255,0,0)
child.rotation = math.random(-1,1)
end
end
end[/lua] [import]uid: 40033 topic_id: 26558 reply_id: 107731[/import]

next post [import]uid: 40033 topic_id: 26558 reply_id: 107730[/import]

Oops, I think I misread your question, not sure I answered what you were looking for, sorry! [import]uid: 40033 topic_id: 26558 reply_id: 107743[/import]

Would this work for you?

local function test(group)  
 print(group["childgroup"]);  
end  
   
   
local maingroup = display.newGroup();  
local childgroup = display.newGroup();  
maingroup["childgroup"] = childgroup;  
test(maingroup);  

or

local function test(group)  
 print(group["childgroup"]);  
end  
   
   
local maingroup = display.newGroup();  
local childgroup = display.newGroup();  
local subGroup = "childgroup"  
maingroup[subGroup] = childgroup;  
test(maingroup);  

[import]uid: 123200 topic_id: 26558 reply_id: 107757[/import]

Thank for all your replys guys, think al either stick with what I did or use victors method

Thanks [import]uid: 102413 topic_id: 26558 reply_id: 107788[/import]