Heyo sorry if the title doesn’t match with the question, but I have a dictionary of moves which has a table for its sequence (the keys you need to press to perform the move) like this.
[3] = {
Name = "Grab";
Sequence = {"G","B"};
},
[4] = {
Name = "Light Punch";
Sequence = {"G"};
};
And I then have a function which is being ran every frame which checks if what was inputted matches a sequence however turns out the code messes up when there’s multiple sequence that start with the same input if I try to perform the Grab move I can’t whenever I input G it will think I’m trying to do Light Punch.
Here’s the function that checks the sequence
local function CheckSequence()
local commandInputIndex = 0 --stores the index of the InputSequence table
local lastMatchIndex = 0 --stores the last matching move
local matchedInputCount = 0 --stores the amount of matching inputs
for moveIndex = 1, #Moveset do
commandInputIndex = ((#InputSequence - 1) + 1) --makes sure that it always stays at 1
matchedInputCount = 0 --sets it to zero for each move in the moveset
for inputIndex = #Moveset[moveIndex].Sequence, 1, -1 do
--"consume" the InputSequence until it is no more or we found our target input.
while (commandInputIndex >= 0) do
if Moveset[moveIndex].Sequence[inputIndex] == InputSequence[commandInputIndex] then
matchedInputCount += 1
break
end
commandInputIndex -= 1
end
end
if (matchedInputCount == #Moveset[moveIndex].Sequence) then
lastMatchIndex = moveIndex
local move = Moveset[lastMatchIndex]
--if CheckIfMoveIsValid(move) then
print("you performed: "..move.Name)
InputSequence = {}
Modules.ClientCombat:MoveInputted(move)
--end
end
end
end
My solution was to loop through all the moves and check if any move starts with the same input and if it does wait a tiny bit to see if a new input is added, but I didn’t manage to make this work. Any solutions?