1
votes

Below is a sample function I have to implement a jumping mechanic in a small platforming game.

function love.keypressed(key)
    if (key == "w" or key == "up" or key == "space") and player.grounded then
        player.grounded = false
        player.yVelocity = player.JUMP
    end
end

The function detects a keypress and based on what key it is, runs the code to let the player jump. The 'w' and 'up' keys work normally, but I try and and press space, nothing happens. I thought the problem was that I was using the wrong name to reference the space key, but according to Love2d's own documentation, it is correct. Note that none of these keys are used anywhere else in the script and so there is no interference from outside code.

2

2 Answers

3
votes

I figured it out before posting but I'll share my answer in case others get stuck. I am apparently using an older version of Love2d and the space key in my version is represented by using an actual space character: " ". Current versions have "space" as the reference.

1
votes

As you said, on old love2d version that was " " but that's "space" now, you can check all the key of your computer just by doing that :

function love.keypressed(key)
  print(key)
end