3

This is driving me insane because it completely violates my attempts to de-buggify it:

int k = keyCode; //keyCode being a variable declared by a keyPress
//in the Processing library
//k and keyCode are working properly.
if ((k - UP)*500 == 0); //int UP=38;
{
 println((k-UP)*500 == 0);
 //some other code here
}

The result? "false" (and by removing the '== 0', a number that isn't 0). As far as I know only when you use the arrow keys (k==37,38,39,40; 38 being UP) make this condition true.

Is there any such inconsistency, and what may cause it? (The strange format of the condition is because it fixed a similar problem with the RIGHT key not working correctly with just k==RIGHT).

BlueShamen
  • 67
  • 7

2 Answers2

8

You have a semicolon after if, so println is always executed.

quant_dev
  • 6,181
  • 1
  • 34
  • 57
5

You had a ; after your if. That makes it an if with an empty statment, followed by an unconditiend block. Just remove the semicolon in the if line.

flolo
  • 15,148
  • 4
  • 32
  • 57