Love Tutorials on headchant.com

General discussion about LÖVE, Lua, game development, puns, and unicorns.
trlestew
Prole
Posts: 9
Joined: Sun Dec 12, 2010 6:55 pm

Re: Love Tutorials on headchant.com

Post by trlestew »

well I tried one sort of updating, I think. I tried setting to if the player has pressed "q", the application will exit. I honestly have no clue what I'm doing...

Code: Select all

function love.keyboard.isDown(q)
  function love.keypressed(q)
  if q == 'escape' then
     love.event.push('q')
  end	 
end


end
User avatar
headchant
Party member
Posts: 105
Joined: Fri Sep 03, 2010 12:39 pm
Contact:

Re: Love Tutorials on headchant.com

Post by headchant »

You only should use one of those functions.

love.keypressed is used on it's own like this:

Code: Select all

function love.keypressed(key)
  if key == "escape" then
     love.event.push('q')
  end    
end
It is a callback function. Search wikipedia if you do not know what that is http://en.wikipedia.org/wiki/Callback_( ... r_science).

love.keyboard.isDown() can be used for checking if something is down. For example in the love.update() function:

Code: Select all

function love.update(dt)
  if love.keyboard.isDown("escape") then
    love.event.push('q')
  end
end
Be aware that this is going to be evaluated every time the update function is called.

The simplest explanation I can give(please correct me if this is wrong):
love.keypressed(key) is a function in which you can check for all kind of keys states, you WRITE this function yourself, yo do not have to call it (love does this for you)
love.keyboard.isDown(key) is a function which checks if a certain key is down, you CALL the function and get a true false response you do not write it

Also see the wiki: http://love2d.org/wiki/love.keypressed and http://love2d.org/wiki/love.keyboard.isDown
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: Love Tutorials on headchant.com

Post by nevon »

trlestew wrote:well I tried one sort of updating, I think. I tried setting to if the player has pressed "q", the application will exit. I honestly have no clue what I'm doing...

Code: Select all

function love.keyboard.isDown(q)
  function love.keypressed(q)
  if q == 'escape' then
     love.event.push('q')
  end	 
end


end
Now that's just weird. Here's how you'd do it:

Code: Select all

function love.keypressed(key, unicode)
    --This callback is run whenever the user presses a key

    if key == "escape" then
        --If that key is escape, quit the game.
        love.event.push('q')
    end
end
trlestew
Prole
Posts: 9
Joined: Sun Dec 12, 2010 6:55 pm

Re: Love Tutorials on headchant.com

Post by trlestew »

What do you mean by Unicode? :/

I thought that was some sort of encryption, what do I need to put there?

Also, I changed the code to the correct example, and still nothing.
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: Love Tutorials on headchant.com

Post by nevon »

trlestew wrote:What do you mean by Unicode? :/

I thought that was some sort of encryption, what do I need to put there?

Also, I changed the code to the correct example, and still nothing.
It's a callback, not a regular function-function. Unicode is simply the unicode number of the key that has been pressed.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Love Tutorials on headchant.com

Post by Robin »

trlestew wrote:What do you mean by Unicode? :/

I thought that was some sort of encryption, what do I need to put there?
You don't need to, you can ignore it. It is especially useful for more advanced usage of love.keypressed.
Help us help you: attach a .love.
trlestew
Prole
Posts: 9
Joined: Sun Dec 12, 2010 6:55 pm

Re: Love Tutorials on headchant.com

Post by trlestew »

Thanks. Now I have that cleared up :p

I finally just noticed the tutorials on the wiki as well, so that's helping.
I have another question, but I think I should search around first.
jumico
Prole
Posts: 4
Joined: Tue Dec 28, 2010 4:21 am

Re: Love Tutorials on headchant.com

Post by jumico »

Thanks for writing the tutorials I liked both of them. I think they are good for quickly learning the basics of lua.
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests