Page 3 of 3

Re: Love Tutorials on headchant.com

Posted: Sun Dec 19, 2010 4:33 pm
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

Re: Love Tutorials on headchant.com

Posted: Sun Dec 19, 2010 4:56 pm
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

Re: Love Tutorials on headchant.com

Posted: Sun Dec 19, 2010 4:59 pm
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

Re: Love Tutorials on headchant.com

Posted: Sun Dec 19, 2010 5:51 pm
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.

Re: Love Tutorials on headchant.com

Posted: Sun Dec 19, 2010 6:03 pm
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.

Re: Love Tutorials on headchant.com

Posted: Sun Dec 19, 2010 6:16 pm
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.

Re: Love Tutorials on headchant.com

Posted: Sun Dec 19, 2010 7:00 pm
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.

Re: Love Tutorials on headchant.com

Posted: Tue Dec 28, 2010 4:43 am
by jumico
Thanks for writing the tutorials I liked both of them. I think they are good for quickly learning the basics of lua.