Hello,
I’m trying to learn to code with Corona so I’m currently messing around with the code but I need some help since I’m getting an error and I can’t seem to figure out what’s wrong with it…?
“Main.lua:61:bad argument #1 to ‘insert’ (table expected, got nil)”
Below you will find a piece of the code.
I find it strange that it gives errors since I’m using the code from one of the tutorials on the site.
Can someone spot what I’m doing wrong here?
Many thanks.
local function createFish()
local newFish = display.newImageRect( “fish.png”, 20, 20)
table.insert( fishTable, newFish )
physics.addBody( newFish, “dynamic”, { radius=10, bounce=0.8 } )
newFish.myName = “fish”
newFish:setLinearVelocity( math.random( 40,120 ), math.random( 20,60 ) )
newFish.x = display.contentWidth + 60
newFish.y = math.random( 500 )
newFish:setLinearVelocity( math.random( -120,-40 ), math.random( 20,60 ) )
endlocal function gameLoop()
– Create new fish
createFish()– Remove asteroids which have drifted off screen
for i = #fishTable, 1, -1 do
local thisFish = fishTable[i]if ( thisFish.x < -100 or
thisFish.x > display.contentWidth + 100 or
thisFish.y < -100 or
thisFish.y > display.contentHeight + 100 )
then
display.remove( thisFish )
table.remove( fishTable, i )
end
end
endgameLoopTimer = timer.performWithDelay( 500, gameLoop, 0 )