Okay let's look at what you tried to do
Code: Select all
for i, v in ipairs(solidTable) do
solidTable[i] = Collider:addRectangle(x * Map.tileWidth, y * Map.tileHeight, Map.tileWidth, Map.tileHeight)
end
What this would do is go through every existing ipair in solidTable and then to reassign it to a new rectangle body. The table is empty and no pairs exist so this doesn't do anything.
Code: Select all
-- first this
solidTable = {x = 0, y = 0, width = 0, height = 0, tileID = 0}
-- and later this
table.insert(solidTable[tileID], {Collider:addRectangle(x * Map.tileWidth, y * Map.tileHeight,
Map.tileWidth, Map.tileHeight)})
This creates a table and assigns some fields in it to zero. Then table.insert tries to insert a rectangle body into solidTable.tileID, which is a number and not a table so this likely raises an error.
So I assume what you're trying to do is create a table and insert the dimensions, tile, and body of each solid tile into it. If you store the body (heh) you don't need the dimensions since the body already has that information. So you really only need to keep the tile and body. Well, the tile is probably a useful thing for the body to know about anyway so lets' just make the body remember which tile it belongs to. After that you really only need to store the body.
Code: Select all
function loadMap()
solidTable = {}
loader = require("AdvTiledLoader.Loader")
loader.path = "assets/maps/"
Map = loader.load("test.tmx")
-- Tile Properties
for name, layer in pairs(Map.tileLayers) do
for x, y, tile in layer.tileData:iterate() do
if tile.properties.Solid then
-- Insert the body at the end of the table
table.insert(solidTable, Collider:addRectangle(x * Map.tileWidth, y * Map.tileHeight,
Map.tileWidth, Map.tileHeight))
-- Assign the tile to the last body in the table. That would be the one we just inserted.
solidTable[#solidTable].tile = tile
end
end
end
end
end
This is unrelated but I highly recommend you store all of your global values in one table. It will make your life a lot easier later on.