Arithmetic on local 'dt' Error
Posted: Tue Jul 08, 2014 11:13 pm
Heya everyone, I'm new here (and kinda new to coding(I've done some stuff before, I understand a little)), and I have a problem with dt. I want to use it to create smooth movements with my character, but i get the error of "attempt to perform arithmetic on local 'dt' (a nil value)". From some videos I've been watching, I was told that dt is a recognized thing.
Here's the code and where the error is:
If you can help, thanks so much
Here's the code and where the error is:
Code: Select all
player = {}
function player.load()
player.x = 5
player.y = 5
player.xvel = 0
player.yvel = 0
player.friction = 7
player.speed = 2250
player.width = 50
player.height = 50
end
function player.draw()
love.graphics.setColor(255,0,0)
love.graphics.rectangle("fill", player.x, player.y, player.width, player.height)
end
--Here is where it says that there's an error:
function player.physics(dt)
player.x = player.x + player.xvel * dt
player.y = player.y + player.yvel * dt
player.xvel = player.xvel * (1 - math.min(dt*player.friction, 1))
end
function player.move(dt)
if love.keyboard.isDown("right") and
player.xvel < player.speed then
player.xvel = player.xvel + player.speed * dt
end
if love.keyboard.isDown("left") and
player.xvel < -player.speed then
player.xvel = player.xvel - player.speed * dt
end
end
--More functions including other functions.
function UPDATE_PLAYER(dt)
player.physics(dt)
player.move(dt)
end
function DRAW_PLAYER()
player.draw()
end