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
SOS! Dt issues!
- Porkinator
- Prole
- Posts: 8
- Joined: Wed Mar 25, 2015 12:58 pm
SOS! Dt issues!
Why so serious, batman?
Re: SOS! Dt issues!
Hi and welcome to the forum.
You need to replace the function declaration of the love.update by this:
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)
You need to replace the function declaration of the love.update by this:
Code: Select all
function love.update(dt)
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)
Check out my blog on gamedev
- Porkinator
- Prole
- Posts: 8
- Joined: Wed Mar 25, 2015 12:58 pm
Re: SOS! Dt issues!
Thanks!micha wrote:Hi and welcome to the forum.
You need to replace the function declaration of the love.update by this:Otherwise the variable dt is not define inside this function.Code: Select all
function love.update(dt)
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)
Why so serious, batman?
Re: SOS! Dt issues!
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
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
Who is online
Users browsing this forum: Ahrefs [Bot] and 3 guests