Keys getting "stuck" problem

Game Editor comments and discussion.

Keys getting "stuck" problem

Postby lverona » Sat Aug 20, 2016 7:58 pm

Hey everyone!

I have been using GE for years and always noticed this bug, but as in my current game it really affects gameplay, decided to ask about it.

The problem is this - I have left and right arrow keys set to walking left and right and space to fire. But what sometimes happens is that although, say, left key is already unpressed, the game thinks the key is still pressed and the player will keep on going left until I pres left key again. It is as if the game misses some of the events or doesn't read the keys correctly.

The code seems to be clean, I have both key down and key up events, where I specifically on key up set flags to not move anymore. But this happens anyway. This happens relatively often and has always happened to me in GE. I just want to know if I can do something to fix it or if it is a known problem. Forum search revealed nothing.
lverona
 
Posts: 221
Joined: Tue Apr 24, 2012 11:54 am
Score: 1 Give a positive score

Re: Keys getting "stuck" problem

Postby lcl » Sat Aug 20, 2016 9:49 pm

An example ged could be useful. I have not had that problem. Are you sure it is nothing about your code?
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Keys getting "stuck" problem

Postby skydereign » Sun Aug 21, 2016 3:49 am

I believe the problem you are running into is a hardware limitation. A lot of keyboards have a limit on the number of keys that one can send to the computer at a given time. Commonly if you press more than the limit, you will skip key releases which sounds like what is happening to you. For the bulk of keyboards I believe the limit is three/four keys depending on the combination of keys. If I remember correctly there isn't too much you can do except try to limit the number of keys you need to press at any given time. If you have a keyboard that supports n key rollover you won't run into this problem.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Keys getting "stuck" problem

Postby lverona » Sun Aug 21, 2016 9:06 am

To be honest, that's what I am thinking. Although it is weird that Key Up messages might be the ones which are not being read (since all xvelocity=0 code is on KeyUp in my code).

The player needs to use left, right down arrows and space to shoot. And, of course, fluent use of these keys will result in several keys pressed at the same time. I wonder if changing which keys the player is using is of any help.
lverona
 
Posts: 221
Joined: Tue Apr 24, 2012 11:54 am
Score: 1 Give a positive score

Re: Keys getting "stuck" problem

Postby lverona » Sun Aug 21, 2016 9:31 am

Also, I find it very difficult to reproduce. It seems to happen at very random times in the game. Very often, but very randomly. And sometimes it feels I haven't pressed more than two keys at a time. If I set to reproduce it - it doesn't happen. As soon as I just begin playing the game - it happens. Maybe during play I press some combination that I don't normally while trying to reproduce...
lverona
 
Posts: 221
Joined: Tue Apr 24, 2012 11:54 am
Score: 1 Give a positive score

Re: Keys getting "stuck" problem

Postby lverona » Sun Aug 21, 2016 12:53 pm

Okay, fellas, I am pasting what could be relevant code. Of course, if this does not help, I will provide the source to try out.

So, here is the Draw event of the player, which handles his collisions. I am using CollisionFree method here.

Code: Select all
//gravity
yvelocity++;view.yvelocity++;if (yvelocity>7){yvelocity=6;view.yvelocity=6;}

//slowing down before landing on something
if(CollisionFree("Event Actor",x,y+yvelocity)==false){
yvelocity=1;view.yvelocity=1;
}

//to make sure we can jump only after we landed on the platform
if(CollisionFree("Event Actor",x,y+1)==false){ yvelocity=0;view.yvelocity=0; jump=1;}


//bumping into obstacles on left and right
if(CollisionFree("Event Actor",x-2,y)==false) {wleft=0;} else {wleft=1;}
if(CollisionFree("Event Actor",x+2,y)==false) {wright=0;} else {wright=1;}


Here is what happens on keydown (this is for LEFT arrow)

Code: Select all
if(wleft==1) {xvelocity=-2;}
else {xvelocity=0;}


And here is what happens on keyup (this is for LEFT arrow)

Code: Select all
xvelocity=0;



So the idea here is that the Draw Actor event checks whether an actor can move, say, left. If he can, then the flag wleft is set to 1. Whereas the keydown event will set xvelocity only if this flag allows it. Then keyup event will set xvelocity back to 0.


What seems to happen

At some point in time one of the keyup events fails to register - or at least so it seems. I even added to the screen pictures of keys, which would change color when I press them and go back to normal on keyup. On occasions of the bug I would see that the picture of the relevant key is in state "pressed".

The biggest problem is that it is not easy to reproduce. When I try to press three keys at the same time, this does not occur. But it does happen during normal gameplay and happens very often, say, every 15-20 seconds. This makes it very frustrating to play. But also extremely difficult to debug.


I also made a screen video of myself playing, to track the situations with the kys when that occurs and was able to catch that several times, but pressing seemingly same combination does not reproduce the error. In fact, I haven't been able to reproduce it even once by pressing the keys on purpose to get the bug. But as soon as i start playing the game, jumping down from platforms and collecting items - that's when this might randomly happen. As if my behavior during the game is slightly different that how I press buttons when trying to reproduce.
lverona
 
Posts: 221
Joined: Tue Apr 24, 2012 11:54 am
Score: 1 Give a positive score

Re: Keys getting "stuck" problem

Postby lverona » Mon Aug 22, 2016 8:14 pm

Hey guys? Can you look at the code above? Does it make sense?
lverona
 
Posts: 221
Joined: Tue Apr 24, 2012 11:54 am
Score: 1 Give a positive score

Re: Keys getting "stuck" problem

Postby skydereign » Thu Aug 25, 2016 10:48 pm

Off hand it seems that it should be fine. I checked my laptop and it seems to have a limit of four normal keys pressed, and will ignore arrow keys when five normal keys are pressed. Interestingly, my laptop seems to acknowledge the keyup events as soon as I release enough keys for it to start tracking, which I remember this to not happen on my old setup. So with that, I don't run into any problems using the code you provided.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Keys getting "stuck" problem

Postby lverona » Mon Aug 29, 2016 7:04 pm

Sky, a suspicion begins to creep in.

I tried the compiled version of the game - and the problem does not occur. Could it be that in Editor mode the game is less loose with the resources? And may not function as well?
lverona
 
Posts: 221
Joined: Tue Apr 24, 2012 11:54 am
Score: 1 Give a positive score

Re: Keys getting "stuck" problem

Postby lverona » Mon Sep 05, 2016 4:28 pm

Sky, what do you think? Could the compiled version be faster and perform more consistently than the version in the editor?
lverona
 
Posts: 221
Joined: Tue Apr 24, 2012 11:54 am
Score: 1 Give a positive score

Re: Keys getting "stuck" problem

Postby skydereign » Tue Sep 06, 2016 1:27 am

I've never run into anything like that myself, and I don't think the editor would be more likely to drop events like that. Can you send me the ged?
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron