Can I add in arrow controls into a game

I’m trying to make a game and instead of adding WASD controls I want to add arrow controls does anyone’s know how?

Hey @lukus_mcd,

You can use this code for arrow keys:

function keyPressed(key) {
    if (key === "UP") {
        doSomething(); 
    }
}

Just swap “UP” with “RIGHT”, “LEFT”, “DOWN”!

Hey Lukus, I didn’t know that you used wick too now! Do you like it? I dont want to say my name online, but I am the one who showed you this software during study hall at emmaus. Anyway, cool your here. see ya

@Luxapodular where should the keyPressed(key) be called at? Like in the update of the layer or in the update of a object…?
I am using Wick editor Alpha and I am not able to get the above mentioned code working.

I used the above code in both update of a layer and in the update of the corresponding object, nothing seemed to work.

Ah just now I am seeing that there is a seperate script tab for KeyPressed in the alpha edition of the Wick, adding the code there solved my issues and I am able to move my object :slight_smile:

1 Like

@surveshJones sorry about the confusion!

Thank you, that helped me a lot …

But I have another question.
I used this command to make a large object up and down, so that it could be seen fully…
But if I continue to press the image it keeps moving.
I wanted to set a limit on how much the object can move. It is possible?

Hey @Magracor,

You can do this by using an “if” statement. If statements are pieces of code that only run if a condition is true.

if (condition) {
  // Run the code inside here if the condition is true.
}

Your condition can be anything that evaluates to true or false like

this.width < 200

Here’s an example that shows how they’re used!

ifStatementDemo.wick (1.8 KB)

Here is the keypressed code on this object. I use && to chain two conditions together which only lets the if statement run if both sub-conditions are true! (The key is “a” AND the width is less than 200)…

// If the key pressed is "a" AND the width of this object is less than or equal to 200.
if (key === "a" && this.width <= 200) {
    // Make the width larger by 10.
    this.width = this.width + 10;
}

Let me know if this helps or you have any other questions!

Sorry, I should have shown the code right away. I tried but it did not work. Maybe I did not get it right.

This is the code. Where exactly would this condition apply?

function keyDown(){
if (keyIsDown(‘UP’)){
this.y += 55;
}
if (keyIsDown(‘DOWN’)){
this.y -= 55;
}
}

Hey Magracor, it looks like you’re using the “live” editor.

You’ll need to do something like this:

function keyDown(){
  if (keyIsDown(‘UP’) && this.y < 300){
    this.y += 55;
  }
  if (keyIsDown(‘DOWN’) && this.y > 0){
    this.y -= 55;
  }
}

Does this help?