Weird bug

So I’m making this brick breaker game and I’m doing an endless mode and I have most of the code but this one line of code makes something weird happen

function EndlessBricks()

local brick = display.newImage(‘brick.png’)

brick.x = math.random(100, 300)

brick.y = math.random(100, 300)

brick.name = ‘brick’

physics.addBody(brick, {density = 1, friction = 0, bounce = 0})

brick.bodyType = ‘static’

bricks.insert(bricks, brick)

end

Whenever I ran this code the bricks wouldn’t appear but if I took out the line that says bricks.insert(bricks, brick) the bricks would appear. Why does this line of code make the bricks disappear and how can I fix it. I need to know because this is a very important line of code and my game won’t work properly without it. Please help.

  1. Please format code posts.

formatyourcode.jpg

  1. Where is bricks created? Show that code too please.   (I am assuming it is a display group.)

  2. This is better than the way you are doing the addBody:

    physics.addBody(brick, ‘static’, {density = 1, friction = 0, bounce = 0}) --brick.bodyType = ‘static’

What is bricks variable in your code? Display group? Is that group visible and not overlapped with other groups/display objects?

Your function is named  EndlessBricks but creates a single brick.

  1. Please format code posts.

formatyourcode.jpg

  1. Where is bricks created? Show that code too please.   (I am assuming it is a display group.)

  2. This is better than the way you are doing the addBody:

    physics.addBody(brick, ‘static’, {density = 1, friction = 0, bounce = 0}) --brick.bodyType = ‘static’

What is bricks variable in your code? Display group? Is that group visible and not overlapped with other groups/display objects?

Your function is named  EndlessBricks but creates a single brick.