Love tutorial about input

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Lovingsoul1337
Citizen
Posts: 53
Joined: Fri Feb 21, 2020 1:26 pm

Love tutorial about input

Post 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
User avatar
darkfrei
Party member
Posts: 1181
Joined: Sat Feb 08, 2020 11:09 pm

Re: Love tutorial about input

Post by darkfrei »

https://love2d.org/wiki/KeyConstant

Code: Select all

love.keyboard.isDown( "space" ) then
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
Bobble68
Party member
Posts: 160
Joined: Wed Nov 30, 2022 9:16 pm
Contact:

Re: Love tutorial about input

Post 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?
Dragon
User avatar
slime
Solid Snayke
Posts: 3133
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Love tutorial about input

Post 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.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 56 guests