Help Inserting objects into groups in a loop

Im trying to insert all objects from 1 group into another. How can i do this? The way i tried was like this:

for k=1,ResultGroup.numChildren do
TestGroup3:insert(ResultGroup[k])
end

but as you might guess, it doesnt work. Help plz [import]uid: 123133 topic_id: 30304 reply_id: 330304[/import]

It makes no sense, object cannot be in two display groups.
If you are inserting it into TestGroup3 you are removing automatically from ResultGroup.
In the end ResultGroup would be empty, and in TestGroup3 will be copy of previous ResultGroup
Run this code to test it yourself

for k=ResultGroup.numChildren,1, -1 do  
 print (ResultGroup.numChildren)  
TestGroup3:insert(ResultGroup[k])   
end  
  
print (" ResultGroup count: " .. ResultGroup.numChildren)  
print (" TestGroup3 count: " .. TestGroup3.numChildren)  

[import]uid: 145499 topic_id: 30304 reply_id: 121395[/import]

I’m not trying to copy a group, i want to remove the ones in 1 group to another, leaving the otherone empty for the next round, because my app plays with this group transitioning. Trust me, it makes perfect sense… Anyway, i resolved the issue myself; the problem was that the value of “k” changes each time (obviously), and in doing so, the value that was in TestGroup3:insert(ResultGroup[2] is no longer in that position after the first loop, it would be in TestGroup3:insert(ResultGroup[1]), therefore by the time it gets to a certain number, there will be no value stored in that index. To solve this I replased TestGroup3:insert(ResultGroup[k]) for TestGroup3:insert(ResultGroup[1]), that way i will ensure getting every single object out of that group due to the index 1 changes every cycle.

I hope this thread can help someone in the future [import]uid: 123133 topic_id: 30304 reply_id: 121430[/import]

It makes no sense, object cannot be in two display groups.
If you are inserting it into TestGroup3 you are removing automatically from ResultGroup.
In the end ResultGroup would be empty, and in TestGroup3 will be copy of previous ResultGroup
Run this code to test it yourself

for k=ResultGroup.numChildren,1, -1 do  
 print (ResultGroup.numChildren)  
TestGroup3:insert(ResultGroup[k])   
end  
  
print (" ResultGroup count: " .. ResultGroup.numChildren)  
print (" TestGroup3 count: " .. TestGroup3.numChildren)  

[import]uid: 145499 topic_id: 30304 reply_id: 121395[/import]

I’m not trying to copy a group, i want to remove the ones in 1 group to another, leaving the otherone empty for the next round, because my app plays with this group transitioning. Trust me, it makes perfect sense… Anyway, i resolved the issue myself; the problem was that the value of “k” changes each time (obviously), and in doing so, the value that was in TestGroup3:insert(ResultGroup[2] is no longer in that position after the first loop, it would be in TestGroup3:insert(ResultGroup[1]), therefore by the time it gets to a certain number, there will be no value stored in that index. To solve this I replased TestGroup3:insert(ResultGroup[k]) for TestGroup3:insert(ResultGroup[1]), that way i will ensure getting every single object out of that group due to the index 1 changes every cycle.

I hope this thread can help someone in the future [import]uid: 123133 topic_id: 30304 reply_id: 121430[/import]