Fairly normal. To actually have the value of dt, you have to place the right part of your code in a callback function.
Inside love update, precisely.
Roughly, you have to separate your code into pieces, and each piece goes into the right callback. Those callbacks functions are fired by löve, so you do not have to handle them.
Code: Select all
function love.load()
-- this is where goes all the code the init things, and it is fired once
-- at the very start of the game
end
function love.updated(dt)
-- Here, you can get the value of dt. This callback is called periodically, each tick time,
-- so this is where goes to update things (dynamics, movement, etc).
end
function love.draw()
-- This is where you draw/render all your entities and stuff
end
See
callbacks, for more details on this.
In your case, you can have this layout:
Code: Select all
function love.load()
player = {}
player.xvel = 0
player.spe = 144000
function player.move(dt)
if love.keyboard.isDown("d") then
player.xvel = player.xvel + (player.spe * dt)
elseif love.keyboard.isDown("a") then
player.xvel = player.xvel - (player.spe * dt)
end
end
end
function love.update(dt)
player.move(dt) -- pass the dt value to the function!
end
function love.draw()
player.draw() -- eventually, if defined.
end
This might contains some typos, I wrote it from scratch, but hope you get the logic.
And that's your first Löve story, huh ? Welcome to Löve, then!
Hope this helps.