Code stops working when using onKeyDown inside of player variable Kaboom.js

Question:
How do I fix this bug inside of Kaboom javascript? Whenever I enter components such as scale, position, area, and body nothing happens, however, when I put the onKeyDown event inside of the player variable, it starts coming up with the error “Duplicate comment property: paused”. I’ve never seen this error before, and it’d be very much appreciated if some of you here in replit would help me solve this issue.
Repl link/Link to where the bug appears:
https://replit.com/@appleset/kaboom-5?v=1
Screenshots, links, or other helpful context:
Here’s the code:

const player = add([
  sprite("bean"),
  scale(.5),
  pos(100,100),
  area(),
  body(),

onKeyDown("right", () => {
  player.move(50,0)
})
])
1 Like

Hello @appleset and welcome to the community!

Try to use onKeyDown() instead of player.onKeyDown

// player movement 
onKeyDown("right", () => {
  player.move(70, 0);
});

onKeyDown("left", () => {
  player.move(-70, 0);
});

onKeyDown("space", () => {
  if (player.isGrounded()) {
    player.jump(350);
  }
});
2 Likes