Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when using tiles iterator #4

Open
DominikStyp opened this issue Oct 9, 2020 · 2 comments
Open

Error when using tiles iterator #4

DominikStyp opened this issue Oct 9, 2020 · 2 comments

Comments

@DominikStyp
Copy link

DominikStyp commented Oct 9, 2020

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'

@tesselode
Copy link
Owner

Can you provide an example project that demonstrates the issue?

@tesselode
Copy link
Owner

Actually never mind, I think I know what your issue is.

Try changing:

	local allTiles = layer:getTiles()
	for v in allTiles do
	      print(v)
	end

To:

	for v in layer:getTiles() do
	      print(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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants