Tile map drawing (Drawable expected, got nil)

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
AlexCalv
Prole
Posts: 49
Joined: Fri Aug 08, 2014 7:12 pm
Contact:

Tile map drawing (Drawable expected, got nil)

Post by AlexCalv »

This is map drawing code

Code: Select all

function draw_map()
	for y = 1, map_display_h do
		for x = 1, map_display_w do
			love.graphics.draw(tile[map[y+map_y][x+map_x]],0,0)
			--love.graphics.draw(tile[map[2][2]],0,0)
			--love.graphics.draw(tile[level[y][x]], x*50, y*50)
			--love.graphics.draw(tiles, x*50, y*50)
			--love.graphics.draw(tile[map[y+map_y][x+map_x]],(x*tile_w)+map_offset_x,(y*tile_h)+map_offset_y)
		end
	end
end
and there is the other tile related stuff inside love.load()

Code: Select all

	tile = {}
	for i = 0, 2 do
		tile[i] = love.graphics.newImage("tile" ..i.. ".png")
	end

	map_display_w = 25
	map_display_h = 9
	map_x = 0
	map_y = 0

	map={"0000000000000000000000000",
		 "0111111111111111111111110",
		 "0111111111111111111111110",
		 "0111111111111111111111110",
		 "0111111111111111111111110",
		 "0111111111111111111111110",
		 "0111111111211111211111110",
		 "0111211111111111211112110",
		 "0000000000000000000000000",
		}
I'm just sitting here very confused because I've followed the tutorial on the wiki almost to a tee and it simply won't draw the map.
User avatar
zorg
Party member
Posts: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Tile map drawing (Drawable expected, got nil)

Post by zorg »

It may be an issue with lua not allowing you to index strings like tables? Your first code block treats map as a 2 dimensional table, but the second one has it be a 1D one with strings in it. You can't index strings with [].
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
AlexCalv
Prole
Posts: 49
Joined: Fri Aug 08, 2014 7:12 pm
Contact:

Re: Tile map drawing (Drawable expected, got nil)

Post by AlexCalv »

zorg wrote: Thu Apr 05, 2018 2:04 am It may be an issue with lua not allowing you to index strings like tables? Your first code block treats map as a 2 dimensional table, but the second one has it be a 1D one with strings in it. You can't index strings with [].
Yeah I ended up taking a nap and fixed it when I woke up. The map needed to be setup like so

Code: Select all

map={
	{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
	{0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0},
	{0,0,0,0,0,1,0,1,0,1,0,2,0,0,2,0,1,0},
}
Just an oversight on my part really, now I just need to figure out why my tiles are being loaded diagonally instead of in a square grid.
User avatar
pgimeno
Party member
Posts: 3672
Joined: Sun Oct 18, 2015 2:58 pm

Re: Tile map drawing (Drawable expected, got nil)

Post by pgimeno »

AlexCalv wrote: Thu Apr 05, 2018 2:31 am Just an oversight on my part really, now I just need to figure out why my tiles are being loaded diagonally instead of in a square grid.
Are you using quads? That sounds like passing a wrong horizontal size while creating the quad (the image size parameter, not the quad size parameter).
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 5 guests