Hello, to train myself using Corona I’m making a flappy bird clone,
Everything was fine until I encounters this error:
main.lua:90: bad argument #-1 to ‘addBody’ (Proxy expected, got nil)
I couldn’t find any solution and for fact if I call the function outside the gameLoop, oddly it works anyone got an idea of what I did wrong?
-------------------------------------------------------------------------- local pipefile = -- { -- frames = { -- { -- up -- x = 77, -- y = 10, -- width = 26, -- height = 115 -- }, -- { -- down -- x = 77, -- y = 153, -- PIPES width = 26, -- height = 107 -- }, -- } -- } -- -- local pipesheet = graphics.newImageSheet( "pipes.png", pipefile ) -- -- pipes = { -- ["up"] = display.newImageRect( mainGroup, pipesheet, 1, 40, 200 ), -- ["down"] = display.newImageRect( mainGroup, pipesheet, 2, 40, 200 ) -- } -- -------------------------------------------------------------------------- --function that errors-- local function createPipe(y) local newPipe = pipes.down table.insert( pipesTable, newPipe ) physics.addBody( newPipe, "kinematic", { radius=40, bounce=0.8 } ) --LINE 90 newPipe.myName = "pipe" newPipe.x = display.contentCenterX\*2 newPipe.y = display.contentCenterY\*1.5 + y newPipe:setLinearVelocity( -100, 0 ) newPipe:applyTorque( math.random( 10,10 ) ) end --where it's called-- local function gameLoop() createPipe(math.random(2,4)) for i = #pipesTable, 1, -1 do local thisPipe = pipesTable[i] if thisPipe.x \< 1000 then display.remove( thisPipe ) table.remove( pipesTable, i ) end end end gameLoopTimer = timer.performWithDelay( 500, gameLoop, 0 )
(this is not the entire code but only the part that seems to be important)