
Originally Posted by
hexpunK
Sorry for the bump, but this is useful after all. Anyway, I have a slight problem with Expression, I am trying to make a simple little Tank Controlling expression, problem is I can get the wheels to turn how I need, but they don't stop, then when i add something to make them stop, they don't turn. I know I am probably missing something important, I just can't figure out what it is.
Code:
N@Tank Controls
I@W A S D
O@Left Right
W == 1 -> Left=1 Right=1;
W == 0 -> Left=0 Right=0;
A == 1 -> Left=-1 Right=1;
A == 0 -> Left=0 Right=0;
S == 1 -> Left=-1 Right=-1;
S == 0 -> Left=0 Right=0;
D == 1 -> Left=-1 Right=1;
D == 0 -> Left=0 Right=0;
Any help is appreciated.
Absolutely, this thread is intended to help people so ask as much as you want.
Your problem is quite common actually, if you look closely at each of your keys, you'll notice they are either PRESSED or NOT PRESSED. And depending on which it is, you set _ALL_ the parameters. Meaning, that any previous changes will have no effect.
This is one way of fixing it: (Also, note that you don't have to write == 1)
Code:
N@Tank Controls
I@W A S D
O@Left Right
Left = Right = 0
W -> Left=1, Right=1;
A -> Left=-1, Right=1;
S -> Left=-1, Right=-1;
D -> Left=1, Right=-1;
EDIT: And I could recommend switching to Expression2, it is superiour in every way, your code would look like this in E2 if you want to try it out (it also support if-else-statements which are really handy):
Code:
@name Tank Controls
@inputs W A S D
@outputs Left Right
Left = Right = 0
if(W) { Left=1, Right=1 }
if(A) { Left=-1, Right=1 }
if(S) { Left=-1, Right=-1 }
if(D) { Left=1, Right=-1 }
Bookmarks