When I hold right arrow key to move a hero right and, while still holding this key, I press left arrow key to go left, but the game doesn’t recognize the released action and do not stop moving right The same problem appears when a space key is pressed down.
How do I properly deal with multiple keyboard input? What am I missing or missunderstanding?
Below is a module function I’m using in go script’s on_input. The module uses Platypus and self.dir is used to specify if it should go left/right or not move at all.
function MOVE:on_input(action_id, action)
if action.pressed then
if action_id == hJUMP then -- click jump
self:jump(true)
d.log(d.MOVE, "clicked jump")
elseif action_id == hLEFT then
self.dir = u.left
d.log(d.MOVE, "clicked left")
elseif action_id == hRIGHT then
self.dir = u.right
d.log(d.MOVE, "clicked right")
end
end
if action.released then
if action_id == hJUMP then
d.log(d.MOVE, "jump released")
self:jump(false)
elseif (action_id == hLEFT) or (action_id == hRIGHT) then
d.log(d.MOVE, "direction keys released")
self.dir = u.stop
end
end
end
I needed it for stopping a go. Normally I would check each frame for an input status, but since it is possible to check only key state’s change it is convenient to stop a go at release. But as I described above, it’s a problem with handling those actions and not input itself, so the solution I made for now is to count left and right keys press and at every release decreasing this counter, and when it reaches 0 then to stop a go. For now it works, but I’ll see if it’s stable and then share it