Compare multiple strings in if statement, what is wrong?

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.

Thank you very much.
Best regards
JohannesTN

Try brackets like this?

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'm not sure if that will work but by my thinking it should see if one or more of the ps2x parts is true, then and that with kort.

If that doesn't work, try this:

else if (kort == true){
     if (ps2x.Analog(PSS_LY) > 100 || ps2x.Analog(PSS_LY) < 140 || ps2x.Analog(PSS_RY) > 90 || ps2x.Analog(PSS_RY) < 130) {

So the second line will only get tested if the firast line is true.

It's hard to tell from a snippet, but I suspect what you meant was this:

else if (kort && ((ps2x.Analog(PSS_LY) > 100 && ps2x.Analog(PSS_LY) < 140) || (ps2x.Analog(PSS_RY) > 90 && ps2x.Analog(PSS_RY) < 130)))

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.

ps2x.Analog(PSS_LY) > 100 && ps2x.Analog(PSS_LY) < 140)

the ps2xAnalog() call is done twice (4x) with the same (2) parameter.
Is it possible that the return value changes between those two calls?

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 :slight_smile: - I'll write you back to let you know if it worked or not.

Thank you.
best regards
JohannesTN

Update:
I got it working by using JimboZA'z method, thank you very much to all of you for your fast help, it's nice to see so many helpful people here :slight_smile:

best regards
JohannesTN