I'm trying to build my own keyboard input state machine. It's my first ever state machine and warning: I'm a new programmer.
I need to differentiate between:
- Key just pressed
- Key pressed and held down
- Key just released
- Key not pressed
I've been using https://github.com/ndee85/gBot/blob/master/projectfolder/scripts/input_states.gd as a test to prototype but am finding it buggy and to be honest I want to learn how to do it myself.
I'm slowly getting to grips with his code but wanted to ask a question that I don't understand in his code.
He is calling the check() function each time a key is pressed.
It appears check() is then remembering the last state so it can update its current state.
How can it do that if the function is being called anew each time?
I would have thought if I called a function like check() in his code it would simply come in to a fresh, newly access function and be resetting itself and its variables each time.
What am I missing here? I really want to understand this so I can create my own version and control it properly.
Any help or advice would be greatly appreciated. Rob