The Tile System does not work

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.
User avatar
ArchAngel075
Party member
Posts: 319
Joined: Mon Jun 24, 2013 5:16 am

Re: HELP ME

Post by ArchAngel075 »

think why would that be empty, should it be empty?

scratch that - it seems this line :

Code: Select all

 tileI[y + mapY] = {}
is the issue, since this table is being created each time and then you try to access a index in that table (tileI[y + mapY][index])
this WILL fail with nil index error since its a empty table?

EDIT

Is there anything that can be done to replicate the error? as right now im not getting any issues running the program (i can move right only though)
Last edited by ArchAngel075 on Sun Sep 13, 2015 5:46 pm, edited 1 time in total.
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

Re: HELP ME

Post by Doctory »

I don't know how to fix this, but please. Make more meaningful titles. Have you actually read what you need to do to make a proper post?
Leap of Time
Prole
Posts: 23
Joined: Fri Sep 11, 2015 9:20 pm

Re: HELP ME

Post by Leap of Time »

Ok well FUCK!!! That wasn´t even the bug... the bug on this one was the if (don´t know why) the real bug is in the mapY
I don´t know why, but I can`t use the mapY, as soon as I change it, it crashes.
I will send the source code, where it crashes, and I will attach the file:

The code:

Code: Select all

--main.lua
--LÖVE
lib = require("lib.mainLib")
keyListener = require ("lib.keyListener")
require("maps.map1")

function love.load()
	WIDTH = 1240
	HEIGHT = WIDTH / 16 * 10
	love.window.setMode(WIDTH, HEIGHT)
	
	--love.window.setFullscreen(true, "desktop")
	
	playerRightNoKnife = love.graphics.newImage("resources/entitys/Spieler (Gehen ohne Klingen, transparent).png")
	playerLeftNoKnife = love.graphics.newImage("resources/entitys/Spieler (Andere Richtung gehen ohne Klingen, transparent).png")
	--player = lib.animationArray(6, 190, 19 - 1, 50, 80, -54, playerLeftNoKnife)
	player = lib.animationArray(6, 40, 19, 50, 70, 54, playerRightNoKnife)
	playerP = playerRightNoKnife
	
	oneTime = true
	
	px = 1
	py = 1
	
	mapMotX = 0
	mapMotY = 0
	mapSX = 0
	mapSY = 0
	
	timer = 0
	iterator = 0
	max = 3
	moving = false
	direction = "left"
	
	onetime = true
	secondtime = false
	jumping = false
	
	--if abcde == nil then love.event.quit() end
	
	tileIndexer = {}
	for i = 1, 1000 do
		tileIndexer[i] = {}
		for o = 1, 1000 do
			tileIndexer[i*o] = {}
			tileIndexer[i+o] = {}
			tileIndexer[i-o] = {}
			tileIndexer[i/o] = {}
		end
	end
	
	loadTiles()
	loadMap1()
end


function love.update(dt)
	if tileIndexer[math.floor((love.window.getHeight() / 2) + tileSize * 2)][math.floor(love.window.getWidth() / 2 + mapX - 10 - tileSize * 1)] ~= 0 and direction == "left" and moving then mapMotX = 0 ; moving = false ; iterator = 0 end
	if not jumping and tileIndexer[math.floor(love.window.getHeight() / 2 + tileSize * 4 + 1)][math.floor(love.window.getWidth() / 2 + mapX - 10)] == 0 then mapMotY = 10 end
	mapSX = mapSX + mapMotX * dt
	mapSY = mapSY + mapMotY * dt
	mapX = math.floor(mapSX)
	mapY = 1
	
	
	px = love.window.getWidth() / 2 - 15
	py = love.window.getHeight() / 2 + 5
	
	if secondtime and onetime then
		mapSX = 0
		onetime = false
	end
	secondtime = true
	
	if direction == "right" and moving then playerP = playerRightNoKnife player = lib.animationArray(6, 40, 20, 50, 70, 54, playerRightNoKnife) end
	if direction == "left" and moving then playerP = playerLeftNoKnife player = lib.animationArray(6, 190, 20 - 1, 50, 80, -54, playerLeftNoKnife) end
	
	if moving then
		timer = timer + dt
		if timer > 0.21 then
			timer = 0
			iterator = iterator + 1
			if iterator > max then
				iterator = 0
			end
		end
	end
end

function love.draw()
	drawMap()
	love.graphics.draw(playerP, player[iterator], px, py)
	--the block under the player tileIndexer[math.floor(love.window.getHeight() / 2 + tileSize * 4 + 1)][math.floor(love.window.getWidth() / 2 + mapX - 10)]  x = 768, 608 y = 464
	--the block left in the middle of the player tileIndexer[math.floor((love.window.getHeight() / 2) + tileSize * 2)][math.floor(love.window.getWidth() / 2 + mapX - 10 - tileSize * 1)]
	--(love.window.getHeight() / 2) + tileSize * 2)
	love.graphics.print(math.floor((love.window.getHeight() / 2) + tileSize * 3), 200, 100)
	love.graphics.print(math.floor(love.window.getWidth() / 2 + mapX), 300, 100)
	love.graphics.print(mapSY, 400, 100)
	
end

function love.keypressed(key)
	if key == "escape" then lib.save() end
	if key == "d" then moving = true ;  direction = "right" ; mapMotX = 14 end
	if key == "a" and tileIndexer[math.floor((love.window.getHeight() / 2) + tileSize * 2)][math.floor(love.window.getWidth() / 2 + mapX - 10 - tileSize * 1)] == 0 then moving = true ;  direction = "left" ; mapMotX = -14 end
end

function love.keyreleased(key)
	if key == "d" then moving = false ;  direction = "right" ; iterator = 0 ; mapMotX = 0 end
	if key == "a" then moving = false ;  direction = "left" ; iterator = 0 ; mapMotX = 0 end
	if key == "d" and love.keyboard.isDown("a") and tileIndexer[math.floor((love.window.getHeight() / 2) + tileSize * 2)][math.floor(love.window.getWidth() / 2 + mapX - 10 - tileSize * 1)] == 0 then moving = true ; direction = "left" ; mapMotX = -14 end
	if key == "a" and love.keyboard.isDown("d") then moving = true ; direction = "right" ; mapMotX = 14 end
end

function loadTiles()
	tileSize = 16
	tile = {}
	tileIndex = {}
	tileI = {}
	tile[0] = love.graphics.newImage("resources/tiles/Tile0.png")
	tileIndex[0] = 0
	for i=1,4 do
		tile[i] = love.graphics.newImage( "resources/tiles/Tile"..i..".png" )
		tile[i]:setFilter("nearest", "linear")
		tileIndex[i] = i
	end
end

function loadMap1()
	renderHeight = 100
	renderWidth = 79
	mapX = 0
	mapY = 0
	map = requestMap1()
end

function drawMap()
	for y = 1, #map do
		if y + mapY < renderHeight then
			for x = 1, #map[y] do
				--love.graphics.print(x + mapX, x * tileSize - tileSize / 2, y * tileSize - tileSize)
				if y + mapY ~= nil then love.graphics.print(y + mapY, x * tileSize - tileSize, y * tileSize - tileSize) end
				if x + mapX < renderWidth and y + mapY < renderHeight then if tile[map[y + mapY][x + mapX]] == nil then else love.graphics.draw(tile[map[y + mapY][x + mapX]], x * tileSize - tileSize, y * tileSize - tileSize, 0, tileSize / tile[map[y + mapY][x + mapX]]:getWidth(), tileSize / tile[map[y + mapY][x + mapX]]:getHeight()) end end
				tileI[y + mapY] = {}
				--print(y + mapY, x + mapX)
				--print(map[y + mapY],#map)
                --print(map[y + mapY][x + mapX],#map)
                --print(tileI[y + mapY][x + mapX],#tileI)
                --print(tileIndex[map[y + mapY][x + mapX]],#tileIndex)
				tileI[y + mapY][x + mapX] = tileIndex[map[y + mapY][x + mapX]]
				playerTileDetect(y, x, mapY, mapX)
				--love.timer.sleep(0.05)
			end
		end
	end
end

function playerTileDetect(y, x, mapY, mapX)
	for i = 1, tileSize do
		tileIndexer[y * tileSize - tileSize + i][x * tileSize - tileSize + i] = tileI[y + mapY][x + mapX]
		for o = 1, tileSize do
			tileIndexer[y * tileSize - tileSize + i][x * tileSize - tileSize + o] = tileI[y + mapY][x + mapX]
		end
	end
	--love.graphics.print(x * tileSize - tileSize + 1, x * tileSize - tileSize, y * tileSize - tileSize)
	--love.graphics.print(x * tileSize - tileSize + 1, 100 * x + x, 200 * y + x)
	--love.graphics.print(tileIndexer[y * tileSize - tileSize + 1][x * tileSize - tileSize + 1], x * tileSize - tileSize, y * tileSize - tileSize)
	--tx = tileIndexer[math.floor(love.window.getHeight() / 2 + 5)][math.floor(love.window.getWidth() / 2 - 15)]
end

Attachments
main.love
(50.74 KiB) Downloaded 76 times
Leap of Time
Prole
Posts: 23
Joined: Fri Sep 11, 2015 9:20 pm

Re: The Tile System does not work

Post by Leap of Time »

On this .love file you can move around??? I can´t! It says main.lua:143 attepmt to index a nil value
Attachments
main.love
(50.74 KiB) Downloaded 77 times
Last edited by Leap of Time on Sun Sep 13, 2015 6:23 pm, edited 1 time in total.
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: The Tile System does not work

Post by arampl »

You already changed something. Previous .love was useable (without prints).
Leap of Time
Prole
Posts: 23
Joined: Fri Sep 11, 2015 9:20 pm

Re: The Tile System does not work

Post by Leap of Time »

I couldn´t use any of them...?!?
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: The Tile System does not work

Post by arampl »

Leap of Time wrote:I couldn´t use any of them...?!?
Sorry, I meant the first one uploaded.
Leap of Time
Prole
Posts: 23
Joined: Fri Sep 11, 2015 9:20 pm

Re: The Tile System does not work

Post by Leap of Time »

I can´t use that one either. So, any solution?
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: The Tile System does not work

Post by arampl »

I found that your map height is 52 tiles , but you try to index 53rd (y + mapY).
If you change your loop to for example: "for y = 1, #map - 1 do" then it will work as in first uploaded file.
But you say you can't run it too... Strange...
Leap of Time
Prole
Posts: 23
Joined: Fri Sep 11, 2015 9:20 pm

Re: The Tile System does not work

Post by Leap of Time »

THANK YOU VERY MUCH!!! It works! I can fall now, I didn´t do - 1, I made it - mapY so if mapY isn´t 1 it will still work!
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 3 guests