• Hey! Guest! The 40th (!!!) GMC Jam will take place between February 25th, 12:00 UTC to March 1st 12:00 UTC. Why not join in this very special anniversary jam! Click here to find out more!

GML [KNOWN BUG -- MACOS COMMAND KEYS] State machine glitch - inputs from one state (stationary) repeating infinitely when returning to free state



I have a state machine and the "playerStateHide" has some issue with executing that I can't seem to figure out. I know it has to do with calling playerStateFree at the end of the hide function, as when I remove that line of code and mapped playerStateFree to a keybind, the glitch did not occur. I've also tried setting speed = 0 (and all my movement variables, inputMagnitude = 0, hSpeed = 0, vSpeed = 0, etc...) before the playerStateFree is called, but that causes this to happen instead:



My code is below. Any help would be greatly appreciated!

State machine script:
GML:
// ----------------------------FREE STATE
function playerStateFree(){
//Movement
hSpeed = lengthdir_x(inputMagnitude * speedWalk,inputDirection);
vSpeed = lengthdir_y(inputMagnitude * speedWalk,inputDirection);

playerCol();

//Update Sprite Index
var _oldSprite = sprite_index;
if (inputMagnitude !=0)
{
    direction = inputDirection;
    sprite_index = spriteWalk;
} else sprite_index = spriteIdle;

if (_oldSprite != sprite_index) localFrame = 0;

AnimateSprite();
ChangePlayerState();
}

// ----------------------------HIDE STATE
function playerStateHide(){

hSpeed = lengthdir_x(inputMagnitude * speedHide,inputDirection);
vSpeed = lengthdir_y(inputMagnitude * speedHide,inputDirection);

playerCol();

//Update Sprite Index
var _oldSprite = sprite_index;
sprite_index = spriteHide;
if (_oldSprite != sprite_index) localFrame = 0;

AnimateSprite();

if (!keyHide) state = playerStateFree;

}
// ----------------------------CHANGE STATE
function ChangePlayerState() {
    
    if (keyHide)
    {
        state = playerStateHide;
    }
}
Player step event:
GML:
keyLeft = keyboard_check(vk_left) || keyboard_check(ord("A"));
keyRight = keyboard_check(vk_right) || keyboard_check(ord("D"));
keyUp = keyboard_check(vk_up) || keyboard_check(ord("W"));
keyDown    = keyboard_check(vk_down) || keyboard_check(ord("S"));
keyDash    = keyboard_check_pressed(vk_shift) || keyboard_check_pressed(ord("Z"));
keyHide    = keyboard_check(vk_control) || keyboard_check(vk_lcommand) || keyboard_check(vk_rcommand) ||  keyboard_check(ord("X"));
keyActivate = keyboard_check_pressed(vk_space) || keyboard_check(ord("E"));

inputDirection = point_direction(0,0, keyRight - keyLeft, keyDown - keyUp);
inputMagnitude = (keyRight - keyLeft != 0) || (keyDown - keyUp != 0);

if (!global.gamePaused) script_execute(state);
 

TheouAegis

Member
Does the error occur regardless of how many keys you are actually pressing? Or does the error only occur when you are trying to move while hiding? That would be a case of keyboard ghosting.
 

TheouAegis

Member
And it is happening with control and with x also, not just with the command keys? This would be the first time I heard of the command keys causing any issues, if that would be the case, but from my own experiences some weird errors occur in programs when something from the operating system responds to key presses at the same time.

One test I would do first and foremost is to add to this line:

Code:
keyHide    = keyboard_check(vk_control) || keyboard_check(vk_lcommand) || keyboard_check(vk_rcommand) ||  keyboard_check(ord("X"));
show_debug_message("Pressed "+string(keyHide));
And then in your Hide State function, put
Code:
show_debug_message("Hiding: "+string(self.keyHide));
 
Yup, it's definitely the command keys. I've completely removed both command keys as any input in the game and pressing them in any state causes the keyboard_check to get stuck as true.

EDIT: I've submitted a bug report.
 
Last edited:
Yup, it's definitely the command keys. I've completely removed both command keys as any input in the game and pressing them in any state causes the keyboard_check to get stuck as true.

EDIT: I've submitted a bug report.
I think I had a similiar issue. I solved it by creating an object which handles the input. this solved my issue with the keyboard check not updating
 
I think I had a similiar issue. I solved it by creating an object which handles the input. this solved my issue with the keyboard check not updating
I tried it in a variety of ways and the command key caused it to get stuck regardless. It's apparently a known bug, you can view the bug report here. Apparently due to MacOS "stealing" the input. It's been a known issue for over a year now, so I hope it gets fixed soon.
 
Top