Hello Forum
I am currently playing around with the PS2X library written by Bill Porter. I've set the following if-statement: else if (kort == true && ps2x.Analog(PSS_LY) > 100 || ps2x.Analog(PSS_LY) < 140 || ps2x.Analog(PSS_RY) > 90 || ps2x.Analog(PSS_RY) < 130) I would like it to function the following way: If kort is true, then check whether one of the "ps2x.Analog(PSS_LY) > xxx" is true too, not all of the "ps2x.Analog(PSS_LY) > xxx" have to match, only one of them has to be true for the if statement to execute.
Right now the only thing it does when I run it is always to run the code in the if-statement, it doesn't matter if the "kort" is true or false, the if statement always executes. If kort is false, but one of the "ps2x.Analog(PSS_LY) > xxx" is true, I don't want the if-statement to run.. How can I solve this, I guess I'm not using the " || " the right way, or something.
Using || in the clauses that test the analog values seems odd - I assume you want to check that they are in a range - 100 to 140 in the first case. Logical or defeats that test: every value is either greater than 100 or less than 140. Logical and is probably what you wanted.
Sorry for not making it clear what "ps2x.Analog(PSS_LY) > xxx" represents. These holds the analog values (0-255) for L3/R3 (for those familiar with Playstation controllers) - the values represented in my if statement, is the value in each direction (L3 x and y axis, and R3 x and y axis) which is measured when the sticks are in center (untouched).
I am currently testing JimboZA's solution, As far as I have come until now, it seems to work - I'll write you back to let you know if it worked or not.