I Debugged for like the whole FUCKING day and I can´t get it to FUCKING work. I don´t understand the error and I made a nil check and only if none of the values are nil it executes it, but it still says, that there is a FUCKING nil in the line.
This is the crash reprot:
"
Error
main.lua:145: attempt to index a nil value
Traceback
main.lua:145: in function `drawMap`
main.lua:91: in function `draw`
[C]: in function `xpcall`
"
Here is my source code:
Code: Select all
--the 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 + mapY 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 + mapX and y + mapY < renderHeight + mapY 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] = {}
if map[y + mapY][x + mapX] ~= nil and tileI[y + mapY][x + mapX] ~= nil and y + mapY ~= nil and tileIndex[map[y + mapY][x + mapX]] ~= nil then tileI[y + mapY][x + mapX] = tileIndex[map[y + mapY][x + mapX]] end -- line 145 the error seems to be here.
playerTileDetect(y, x, mapY, mapX)
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