Best way to handle key presses when using Adv. Pod Controller and E2 chip.

Right now I’m using if and elseif but the problem with these are it will only accept the top one if it’s true and then ignore anything below it. For example using:

if(W) {code goes here}
elseif(A) {code goes here}

W will be the only one active if you press W and A. This is causing problems as it doesn’t allow you to make something move forwards and turn. To get round it so far I have just put an if(W & A) at the top. However as my ‘contraption’ gets more complex so does writing more and more lines for certian combinations and priorities.

What I’m asking is, is there a better way to handle key presses so that multiple keys can be active?

remove the word else.

if (W) {Code}
if (A) {Code}

… It’s that simply? God damn, I’ve studied programming for two years and I didn’t notice that?

[editline]06:59PM[/editline]

Now it doesn’t work unless I hold the bottom if down o_o

Even simpler. Use subtract.


@inputs W A S D
@outputs ForwardBackThruster LeftRightThruster
ForwardBackThruster = W - S
LeftRightThruster = A - D

EDIT:
This is because things like wheels, thrusters, motors, and so on need 1 to go forward, -1 to go back, and 0 to stay still.
When using subtract in this way, that is exactly what you are giving them.
Because:
When you are holding down W it is
1 - 0 = 1
When you are holding down S it is
0 - 1 = -1
And same for A - D