Whenever I try to remove and replace some objects with a for loop I get an error that says:
Runtime error
invalid key to ‘next’
stack traceback:
[C]: ?
[C]: in function ‘(for generator)’
…s/Pictures/design/coronadesign/transmission/main.lua:261: in function <…s>
?: in function <?:214>
12
With the code:<br>for i, avoid in pairs(avoids) do<br> if avoid.y ~= nil and avoid.y > display.viewableContentHeight + 75 then<br> avoid:removeEventListener("touch", avoid)<br> avoid:removeSelf()<br> avoid = nil<br> avoids[i] = nil<br> <br> addavoid()<br> elseif avoid.y ~= nil and avoid.y <= display.viewableContentHeight + 75 then<br> avoid:rotate(2)<br> end<br>end<br>
However, if I put a delay, even of time 0, that seems to clear up the issue: <br>for i, avoid in pairs(avoids) do<br> if avoid.y ~= nil and avoid.y > display.viewableContentHeight + 75 then<br> avoid:removeEventListener("touch", avoid)<br> avoid:removeSelf()<br> avoid = nil<br> avoids[i] = nil<br> <br> timer.performWithDelay(0, addavoid, 1)<br> elseif avoid.y ~= nil and avoid.y <= display.viewableContentHeight + 75 then<br> avoid:rotate(2)<br> end<br>end<br>
[import]uid: 10903 topic_id: 11058 reply_id: 311058[/import] </…s>