Page 1 of 1

Love tutorial about input

Posted: Wed Dec 13, 2023 9:40 pm
by Lovingsoul1337
hi

Is there a mistake ? since doesn't need the keyinput functions above the update function ?

Code: Select all

function love.load()
    love.graphics.setFont(12)
    text = "Nothing yet"
end

function love.update(dt)
   if love.keyboard.isDown( " " ) then
      text = "The SPACE key is held down!"
   end
end

function love.draw()
      love.graphics.print( text, 330, 300 )
end

function love.keypressed( key )
   if key == "return" then
      text = "RETURN is being pressed!"
   end
end

function love.keyreleased( key )
   if key == "return" then
      text = "RETURN has been released!"
   end
end
since in the above description say's this(a different one)
You can find the complete list of keys here. The best place to perform this check is inside the love.update callback: that way we're able to get input from the user and update our variables before drawing our stuff into the screen. So, our modified love.update callback should look like this:

Code: Select all

flove.keyboard.isDown()
end
what is now right ?

thanks for all who help me.

best regards

Lovingsoul1337

Re: Love tutorial about input

Posted: Thu Dec 14, 2023 11:18 am
by darkfrei
https://love2d.org/wiki/KeyConstant

Code: Select all

love.keyboard.isDown( "space" ) then

Re: Love tutorial about input

Posted: Fri Dec 15, 2023 5:48 pm
by Bobble68
darkfrei wrote: Thu Dec 14, 2023 11:18 am https://love2d.org/wiki/KeyConstant

Code: Select all

love.keyboard.isDown( "space" ) then
Honestly it's a bit weird Love doesn't throw an error if you use an invalid key constant - is there a good reason for this?

Re: Love tutorial about input

Posted: Fri Dec 15, 2023 6:54 pm
by slime
It does throw an error if you use an invalid key constant.

That particular tutorial was created almost a decade and a half ago when love's APIs were a little different, there are probably much better ones to look at these days.