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

2019/4/4

Weird Inconsistent Issue with Greenfoot.isKeyDown()

knackchaos knackchaos

2019/4/4

#
Hey everyone, I'm a computer science teacher and I was running my students through how to use if statements when a very weird error happened. Oddly, it was only part of the class even though we were all using the same coding structure. We were learning how to use the Greenfoot.isKeyDown() method as a way to make objects react to key presses using the following structure for the methods:
public void moveLeft(){
      if(Greenfoot.isKeyDown("d")){
           setRotation(90);
           move(1);
      }
}
We had matching code for each direction. Now for most of my students this worked absolutely correctly. For about 20% of the class though, movement would be sluggish to start with and then completely die after about 10 seconds. I could sometimes reset the scenario and then it would start working again, but that didn't always work. Movement controls would then sometimes re-enable after a few seconds of holding a key down, but I couldn't figure out what was going on. I was very confused as this only hit a few students and their code was correct as far as I could tell. Any ideas on what might be going on? Thanks for any replies!
danpost danpost

2019/4/4

#
Since your given code was to only provide the structure, I will ignore the fact that (a) the method name indicates left movement; (b) the "d" key being pressed is usually used for moving right; and (c) the rotation faces the actor to move down -- quite confusing, if you ask me. At any rate, you might check to see if the issue is related to a particular OS. Or, maybe its possible that key contacts are bad on some keyboards. Well, that is about all I can immediately come up with. Best of results.
You need to login to post a reply.