1

I know that the error is caused by the index not existing, but i dont know why it is not existing. I am trying to make a program implemented in the mapDraw method which adds to every wall tile(#) a physics object:

function drawMap()
  objects = {}
  for x,column in ipairs(TileTable) do
    for y,char in ipairs(column) do
      love.graphics.draw(Tileset, Quads[ char ] , (x-1)*TileW, (y-1)*TileH)
      if char == '#' then --addding the physics for collision(walls)--
        objects[objectIndex] = {
          body = love.physics.newBody(world, (x-1/2) * TileW, (x-1/2) * TileH),
          shape = love.physics.newRectangleShape(32, 32),
          fixture = love.physics.newFixture(objects[objectIndex].body, objects[objectIndex].shape, 1)
        }
      end
    end
  end
end

I am only starting out with love2d and game making and would appriciate help, thank you.

2
  • 1
    which line is actually line #60? Commented Dec 29, 2017 at 0:25
  • fixture = love.physics.newFixture(objects[objectIndex].body, objects[objectIndex].shape, 1) Commented Dec 29, 2017 at 11:37

1 Answer 1

1

In the following snippet:

objects[objectIndex] = {
  body = love.physics.newBody(world, (x-1/2) * TileW, (x-1/2) * TileH),
  shape = love.physics.newRectangleShape(32, 32),
  fixture = love.physics.newFixture(objects[objectIndex].body, objects[objectIndex].shape, 1)
}

you are self referencing the table key, while it is being assigned. This is an invalid step in lua. Assign the fixture key a value later:

objects[objectIndex] = {
  body = love.physics.newBody(world, (x-1/2) * TileW, (x-1/2) * TileH),
  shape = love.physics.newRectangleShape(32, 32)
}
objects[objectIndex].fixture = love.physics.newFixture(objects[objectIndex].body, objects[objectIndex].shape, 1)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.