I'm a bit of a newbie here, so forgive my inexperience.
I was using the tutorial to implement the player object, but when I attempted to run it, I got this:
Error
main.lua:24: attempt to index local 'player' (a nil value)
Traceback
main.lua:24: in function 'load'
[C]: in function 'xpcall'
[C]: in function 'xpcall'
Code: Select all
local sti = require "sti"
function love.load()
--Load map file
map = sti("res/map/map.lua")
--Create new dynamic data layer called "Sprites" as the 2nd layer
local layer = map:addCustomLayer("Sprites", 2)
--Error is in this chunk, lets figure it out shall we?
--Get player spawn object
local player
for k, object in pairs(map.objects) do
if object.name == "Player" then
player = object
break
end
end
--Create player object
local sprite = love.graphics.newImage("res/img/sprite.bmp")
layer.player = {
sprite = sprite,
x = player.x,
y = player.y,
ox = sprite:getWidth() / 2,
oy = sprite:getHeight() / 1.35
}
--Draw player
layer.draw = function(self)
love.graphics.draw(
self.player.sprite,
math.floor(self.player.x),
math.floor(self.player.y),
0,
1,
1,
self.player.ox,
self.player.oy
)
--Temporarily draw a point at our location so we know
--That our sprite is offset properly
love.graphics.setPointSize(5)
love.graphics.points(math.floor(self.player.x), math.floor(self.player.y))
end
--Remove unneeded object layer
map:removeLayer("Spawn Point")
end
function love.update(dt)
--Update world
map:update(dt)
end
function love.draw()
--Draw world
map:draw()
end
I be developing stuff.