Search code examples
game-makergame-maker-language

Game Maker Code doing the opposite?


if keyboard_check('D')
{
    x = x + 4
    sprite_index = spr_playerRight
}

As soon as I start the game, the player sprite will start moving to the right. But, as you can see, that shouldn't be happening... right?

When I actually do press D, it does the (Else) portion of the little chunk.

Any idea why this is happening? I'm a bit new to this.

Edit: I was messing around a little and I swapped the code (the IF from the else) and I would not move at the start, but pressing any key would cause me to move.

Another Edit: The fact that the Else would apply any time the D key is not applied made me realize that (if this did work properly) the else on this would intrude on attempts to move other directions (Pressing any button will stop the movement)

Another Edit: I changed the keyboard_check to keyboard_check(vk_right) And it works perfectly fine. I believe this is simple a problem on how I declared the key... How do I declare keys properly?


Solution

  • According to the documentation it should be:

    if keyboard_check(ord('D'))