Page 1 of 1

SOS! Dt issues!

Posted: Wed Mar 25, 2015 1:04 pm
by Porkinator
Help! I'm trying to do a tutorial, but whenever I try to move my 'player', I always get the same error message - 'main.lua:9: attempt to perform arithmetic on global 'dt' (a nil value)' What does this mean and how can I fix it? Here is my code --
function love.load()
player = { x = 200, y = 710, speed = 150, img = love.graphics.newImage('assets/plane.png') }
end
function love.update()
if love.keyboard.isDown('escape') then
love.event.quit()
elseif love.keyboard.isDown('left', 'a') then
player.x = player.x - player.speed * dt
elseif love.keyboard.isDown('right', 'd') then
player.x = player.x + player.speed * dt
end
end
function love.draw()
love.graphics.draw(player.img, player.x, player.y)
end

Re: SOS! Dt issues!

Posted: Wed Mar 25, 2015 1:23 pm
by micha
Hi and welcome to the forum.

You need to replace the function declaration of the love.update by this:

Code: Select all

function love.update(dt)
Otherwise the variable dt is not define inside this function.

By the way: You can make your code much more readable by putting it into code-tags (mark your code and press the "Code" button above the text, when writing a post)

Re: SOS! Dt issues!

Posted: Wed Mar 25, 2015 1:35 pm
by Porkinator
micha wrote:Hi and welcome to the forum.

You need to replace the function declaration of the love.update by this:

Code: Select all

function love.update(dt)
Otherwise the variable dt is not define inside this function.

By the way: You can make your code much more readable by putting it into code-tags (mark your code and press the "Code" button above the text, when writing a post)
Thanks!

Re: SOS! Dt issues!

Posted: Sun Mar 29, 2015 12:18 am
by Jeeper
I would also recommend that you use the "support and development" sub-forum for help, not "General".

This makes it easier for people to find your thread if they have a similar problem, gives you an answer faster and keeps the forums cleaner :)