Problem with movement.
Posted: Fri Jun 06, 2014 8:10 am
This is my first game. Ever. This is also my first forum post. With that out of the way, I would like to discuss my issue.
Since this is my first game, alot of the code I use it based off of tutorials. So...yeah.
I've used this code before, for testing, etc. When I tried to run it this time, I got this error:
Player.lua:22: attempted to perform arithmetic on field "speed" (a nil value)
Traceback:
player.lua:22: in function player_move
main.lua:10: in function update
[C:]in function xpcall
Here's my code:
main.lua
require "player"
function love.load()
end
function love.update(dt)
player_move()
end
function love.draw()
player_draw()
end
player.lua
player = {}
player.X = 400
player.Y = 300
player.Speed = 5
player.Health = 100
player.Damage = 10
player = love.graphics.newImage("Graphics/Main dude/player.jpg")
function player_draw()
love.graphics.draw(player,player.X,player.Y)
end
function player_move()
if love.keyboard.isDown("left") then
player.X = player.X - player.Speed*dt
elseif love.keyboard.isDown("right") then
player.X = player.X + player.Speed*dt
end
end
player = {}
player.X = 400
player.Y = 300
player.Speed = 5
player.Health = 100
player.Damage = 10
player = love.graphics.newImage("Graphics/Main dude/player.jpg")
function player_draw()
love.graphics.draw(player,player.X,player.Y)
end
function player_move()
if love.keyboard.isDown("left") then
player.X = player.X - player.Speed*dt
elseif love.keyboard.isDown("right") then
player.X = player.X + player.Speed*dt
end
end
If anyone can give me any help, tips, whatever. Whatever works. Everything is appreciated.
Since this is my first game, alot of the code I use it based off of tutorials. So...yeah.
I've used this code before, for testing, etc. When I tried to run it this time, I got this error:
Player.lua:22: attempted to perform arithmetic on field "speed" (a nil value)
Traceback:
player.lua:22: in function player_move
main.lua:10: in function update
[C:]in function xpcall
Here's my code:
main.lua
require "player"
function love.load()
end
function love.update(dt)
player_move()
end
function love.draw()
player_draw()
end
player.lua
player = {}
player.X = 400
player.Y = 300
player.Speed = 5
player.Health = 100
player.Damage = 10
player = love.graphics.newImage("Graphics/Main dude/player.jpg")
function player_draw()
love.graphics.draw(player,player.X,player.Y)
end
function player_move()
if love.keyboard.isDown("left") then
player.X = player.X - player.Speed*dt
elseif love.keyboard.isDown("right") then
player.X = player.X + player.Speed*dt
end
end
player = {}
player.X = 400
player.Y = 300
player.Speed = 5
player.Health = 100
player.Damage = 10
player = love.graphics.newImage("Graphics/Main dude/player.jpg")
function player_draw()
love.graphics.draw(player,player.X,player.Y)
end
function player_move()
if love.keyboard.isDown("left") then
player.X = player.X - player.Speed*dt
elseif love.keyboard.isDown("right") then
player.X = player.X + player.Speed*dt
end
end
If anyone can give me any help, tips, whatever. Whatever works. Everything is appreciated.