Hmmm, I think the best way would be maybe to tell you what i’m trying to do conceptually because that is probably where my problem lies.
I am creating a card game that shuffles 52 cards and inserts them as display objects into a table. Each hand some cards are dealt and as each one is dealt they are inserted into one of two groups. At the end of the hand the cards are removed via:
for i = playerGroup.numChildren, 1, -1 do local child = playerGroup[i] child.parent:remove(child) child = nil end for i = dealerGroup.numChildren, 1, -1 do local child = dealerGroup[i] child.parent:remove(child) child = nil end
Now, the problem falls when I get to the end of the deck and have to reshuffle the cards, and try to restart the same process as before.
function reShuffle() if counter \>= 10 then setupCards() backs() counter = 0 playerGroup:toFront() dealerGroup:toFront() end end
So this reshuffles the cards and should basically start with a fresh deck. The counter is reset and the next cards will be dealt from the first index of the table. I believe the problem is happening when the cards are being dealt this time they are trying to be reinserted to the same display group as before (I just realized after typing all of that i’m not having a problem with the array but instead the display group… oops maybe you can still help anyways). Then I get this error:
2/main.lua:197: bad argument #-2 to ‘insert’ (Proxy expected, got nil)
at the line where I am trying to reinsert the card display object into the display group via:
playerGroup:insert(cardTable[cardVal[counter]])
Hope I explained this well enough… any ideas where I might be going wrong?