You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
cartographer = require 'externalLibs.cartographer.cartographer' -- if it's in subfolders
-- load a map
local map = cartographer.load 'map.lua'
function love.load()
local layer = map:getLayer("layer1")
local allTiles = layer:getTiles()
for v in allTiles do
print(v)
end
end
function love.update(dt)
-- update animations
map:update(dt)
end
function love.draw()
-- draw the whole map
map:draw()
end
This code doesn't work, despite that map is drawn on the screen, following error occurs when I try to iterate over tiles:
Error
externalLibs/cartographer/cartographer.lua:649: attempt to perform arithmetic on local 'i' (a nil value)
Traceback
externalLibs/cartographer/cartographer.lua:649: in function '(for generator)'
main.lua:8: in function 'load'
[C]: in function 'xpcall'
[C]: in function 'xpcall'
The text was updated successfully, but these errors were encountered:
Actually never mind, I think I know what your issue is.
Try changing:
localallTiles=layer:getTiles()
forvinallTilesdoprint(v)
end
To:
forvinlayer:getTiles() doprint(v)
end
Similar to ipairs, getTiles returns 3 different values, all of which are needed for the loop to function properly. Since you were assigning getTiles() to only one intermediate variable, you're missing the other two variables.
This code doesn't work, despite that map is drawn on the screen, following error occurs when I try to iterate over tiles:
The text was updated successfully, but these errors were encountered: