1

Kia ora everyone!

I'm trying to make my own input system in Kaboom.js by adding functions like the below and adding each key to a string called i (short for input).

keyPress("j", () => { i.concat("j"); });

Then, I try and console.log i. (i do it like console.log(i);) And for some reason I get nothing. I think it's because it's not logging an update to the string?

Is there a better method I can use, and what is wrong with my program?

Ngā mihi Florence

CassieCodes
  • 57
  • 1
  • 5

1 Answers1

0

If your big long string is called inputString then something like this ought to come close:

let inputString = "";
k.onKeyPress("a", event => {
   inputString.concat("a");
   console.info(inputString);
   console.info(event);
});

Rather than copy this out for every different key you're probably best trying to catch all keypresses and then check the properties of the event to determine if it's a relevant key, not an arrow key etc..

Jeremy Jones
  • 4,561
  • 3
  • 16
  • 26