Hello,
I found an issue in my game in which 2 characters have to be controlled, one with WASD and another with arrow keys. The movement is timer-based and accepts a single input at a time. If during a particular state (say, objectstate.inputs), a movement option is inputted, the relevant character changes state (objectstate.move), moves and a timer begins counting down, and when that timer reaches -1, the object state changes again (objectstate.locked) and no more inputs are accepted.
When I input something for both characters simultaneously on the same frame (say, W and right arrow) the game seemingly picks one input at random. I doubt it has to do with keyboard ghosting or anything like that since it only happens when I input the keys on the same frame and the decision as to which one to go with seems to be random as I said, also I tried different key layouts and it still happens.
The code checks for one of the 4 keys for each object and executes a switch statement (the key definitions are different for each character object):
Formerly I was using keyboard_check instead of keyboard_check_pressed and keyboard_lastkey instead of keyboard_key, though changing it didn't seem to matter. I assume these variables are bad to use since they only store 1 input at a time, whereas I need 2 to be stored at once if I'm inputting the movement simultaneously.
Also I'm using a Draw GUI event and I've confirmed that it simply doesn't pick up one of the inputs when inputted simultaneously.
What should I do?
I found an issue in my game in which 2 characters have to be controlled, one with WASD and another with arrow keys. The movement is timer-based and accepts a single input at a time. If during a particular state (say, objectstate.inputs), a movement option is inputted, the relevant character changes state (objectstate.move), moves and a timer begins counting down, and when that timer reaches -1, the object state changes again (objectstate.locked) and no more inputs are accepted.
When I input something for both characters simultaneously on the same frame (say, W and right arrow) the game seemingly picks one input at random. I doubt it has to do with keyboard ghosting or anything like that since it only happens when I input the keys on the same frame and the decision as to which one to go with seems to be random as I said, also I tried different key layouts and it still happens.
The code checks for one of the 4 keys for each object and executes a switch statement (the key definitions are different for each character object):
GML:
if(keyboard_check_pressed(keyUp||keyDown||keyLeft||keyRight)){
if(keyboard_key == keyUp||keyDown||keyLeft||keyRight)
_press = keyboard_key;
else
_press = 0;
switch(_press){
case keyUp:
movementY = -movement;
validInput = true;
break;
case keyDown:
movementY = movement;
validInput = true;
break;
case keyLeft:
movementX = -movement;
validInput = true;
break;
case keyRight:
movementX = movement;
validInput = true;
break;
}
}
Also I'm using a Draw GUI event and I've confirmed that it simply doesn't pick up one of the inputs when inputted simultaneously.
What should I do?