One key at a time

Hi,

I’m trying to make a game where a stick figure’s movements are controlled by the keyboard. Pretty much everything works, but not exactly the way I want. Left, right, up, and down movements are controlled with the arrow keys. There are times where the stick figure can perform other actions by pressing other keys, like the spacebar. However, if I press an arrow key and spacebar, the figure will move AND perform the action attached to the spacebar. What I would like is a way to ‘lock out’ all other keys when any one key is down. Currently, I am using the following commands, in a function, to detect keys: if (Key.isDown (Key.LEFT)) etc…

Is there a method for locking out the other keys when one key is already pressed?

Thanks!

scigolf

do this:
if(Key.isDown(Key.RIGHT)){
// do the ‘right’ thing.
} else if (Key.isDown(Key.LEFT)){
// do the ‘left’ thing.
} else if (Key.isDown(Key.UP)){
// do the ‘up’ thing.
} else if (Key.isDown(Key.DOWN)){
// do the ‘down’ thing.
} else if (Key.isDown(Key.SPACE)){
// do the ‘space’ thing.
}

by using ‘else if’ instead of 5 ‘if’ statements you are limiting the user to one keypress at a time.
:slight_smile:
jeremy

Thank you!

scigolf

Hey scigolf i tried to make a stick figure run while pressing right. But every thime i hold right it locks on the first frame of the movie clip. How do u make it so that if u hold right it will play the movie clip running while holding right down?