SOS! Dt issues!

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
Porkinator
Prole
Posts: 8
Joined: Wed Mar 25, 2015 12:58 pm

SOS! Dt issues!

Post 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
Why so serious, batman? :crazy:
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: SOS! Dt issues!

Post 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)
User avatar
Porkinator
Prole
Posts: 8
Joined: Wed Mar 25, 2015 12:58 pm

Re: SOS! Dt issues!

Post 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!
Why so serious, batman? :crazy:
User avatar
Jeeper
Party member
Posts: 611
Joined: Tue Mar 12, 2013 7:11 pm
Contact:

Re: SOS! Dt issues!

Post 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 :)
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests