This site requires JavaScript, please enable it in your browser!
Greenfoot back
MrSkyPanda
MrSkyPanda wrote ...

2020/12/8

how do i do an or statement?

MrSkyPanda MrSkyPanda

2020/12/8

#
i'm trying to make it so if the player is not holding down left or right key they character will change its image into a standing position. My teacher told me i could use || for or but i got an error.
1
2
3
4
if(!Greenfoot.isKeyDown(right || left))
        {
            setImage("stand-2.png");
        }
danpost danpost

2020/12/8

#
Test keys individually -- then OR the results. Also key names must be between double quotes.
MrSkyPanda MrSkyPanda

2020/12/8

#
it keeps saying bad operand for binary operator '||' even when they were in double quotes and doing them individually doesnt work either
danpost danpost

2020/12/8

#
MrSkyPanda wrote...
it keeps saying bad operand for binary operator '||' even when they were in double quotes and doing them individually doesnt work either
Please show what you tried.
RcCookie RcCookie

2020/12/8

#
I see what you tried - „if either one of the left and right arrow key is down then execute this“. However, what you say with this in the inner part of the statement is „left or right“, and that would be an or between two strings. You can only use the or operator between two boolean values though. So the proper statement would be: „If either the left key is down or the right key is down then execute this“. Try to express that in java now.
You need to login to post a reply.