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

2023/4/18

I want to assign multiple keys for movement, A and Left Key What would be the code for that ?

TheGoatFighter TheGoatFighter

2023/4/18

#
if(Greenfoot.isKeyDown("a" && "left")) { setLocation(getX()-5, getY()); }
TheGoatFighter TheGoatFighter

2023/4/18

#
It is showing an error and that I can't use &&
danpost danpost

2023/4/18

#
TheGoatFighter wrote...
if(Greenfoot.isKeyDown("a" && "left"))
It is showing an error and that I can't use &&
Of course not. Only boolean values (true/false) can be #AND#ed (using '&&') Also, you do not want the actor to move only if both keys are pressed at the same time. You want "if either key is down", which means you need to #OR# ('||') the boolean values:
if (Greenfoot.isKeyDown("a") || Greenfoot.isKeyDown("left"))
You need to login to post a reply.