My game has a different number of balls per level so at the beginning of each level I am populating a group with all the balls being used for that level.
The group that the balls are stored in is declared only once when the game first loads as follows:
local allBallsGroup = display.newGroup()
At the outset, I create an array to store all the balls i.e the maximum number of balls that can be displayed in any level (which is 10). The idea is that i can use this array every level to populate the allBallsGroup depending on how many balls are required for the level
local ballTable = {}
for i = 1, 10 do
ballTable[i] = display.newGroup()
local ball1Layer1 = display.newImage(ballTable[i],"ballLayer1.png")
local ball1Layer2 = display.newImage(ballTable[i],"ballLayer2.png")
end
So for the first level where there are 10 balls required I populate the allBallsGroup as follows:
for i = 1, numberOfBallsForLevel do
allBallsGroup:insert( ballTable[i] )
end
In the game, if a ball goes out of a fixed area it becomes a dead ball and I remove it as follows:
if (allBallsGroup[i].x \> 340) then
allBallsGroup:remove( i )
end
At the end of the level i also remove any remaining balls as follows:
local function removeAllBalls()
for i = allBallsGroup.numChildren, 1, -1 do
allBallsGroup:remove(i)
end
end
Now this all works fine so far. The problem occurs when I start the next level and attempt to populate allBallsGroup using the same code as used for the first level
for i = 1, numberOfBallsForLevel do
allBallsGroup:insert( ballTable[i] )
end
I am getting the following error for the line of code that says allBallsGroup:insert( ballTable[i] )
**Runtime error
bad argument #-2 to ‘insert’ (Proxy expected, got nil)**
Any ideas why this is not working and how to fix it?
Thanks
Paul
[import]uid: 7863 topic_id: 2792 reply_id: 302792[/import]