How to make input sequence

For my fighting system i need to handle input sequence.What the best way to do it in Defold?
For example i have different sequnces in game A-A-A(punch/punch/punch) A-A-B(punch/punch/kick)
I think i need to hadle input and pause between input. Because if player pressed too fast combination not work, and if player pressed too slow combination not work too.

I think about module that contains sequence of pressed buttons and pause between press.
1)In go script on every input.I add pressed button to module.
2)Then i check is it combination or not. If it combination i do all my work(change animation and etc).And wait next input.
3)On next input i add pause to sequence.
a)If pause too short i clear sequence.
b)If pause too big i clear sequence and add pressed button to sequence.
c)If pause is normal.I add pressed button to sequence.And continue my combination

Is it correct solution or there are some better solutuions?
What the best way to compare input(A-A-A) with combination list?To understand what combination user pressed?

Hello,

For these cases, the most usual approach is to use the Command Pattern, and there are many sources where you can find its implementation.

Here is one of those, from a book I love: Command Pattern - Game Programming Patterns by Robert Nystrom

Also, you can think of it as a Finite State Machine:

And here’s an almost identical question in stackoverflow where you define a move like (pseudocode):

const ButtonBuffer HADOKEN_MOVE("D","DF","F");

if ( buttons_pressed.contains(HADOKEN_MOVE) )
{
   // do hadoken
}

Hope it helps

Cheers!

EDIT: You can search the web for terms like: Buffered Input, Input Squence, Command Pattern

3 Likes