I’m trying to get if a player has 3 of the same dragon in a row, they merge together. So if slot 1, 2, 3 all have dragon 1, when then Slot 1 becomes Dragon 2, slot 2 and 3 become empty.
What I have works with that, but it’s other areas where it stops working. I can do 1,2,3 then merge, then 2,3,4, merge. but when slots 1,2 have value of 2, and slots 3,4,5 have value 1, it doesn’t get that those 3 are in a row.
Image here shoes that 3,4,5 are all the same value, but it never prints “MERGE” for them.
Should be
[1] = 2,
[2] = 2,
[3] = 2
in the above screenshot
local CurrentDragonIndex = 1
local InARow = 0
for slotIndex, dragonIndex in Data.Dragons do
InARow += 1
print("SLOT", slotIndex, "DRAGON", dragonIndex, "ROW", InARow, "CURRENT DRAGON", CurrentDragonIndex)
if dragonIndex ~= CurrentDragonIndex then -- Reset
print("RESET!!, Setting Current dragon", CurrentDragonIndex, "to", Data.Dragons.__Origin[slotIndex + 1])
InARow = 0
CurrentDragonIndex = Data.Dragons.__Origin[slotIndex + 1] -- Set to next dragon
end
if InARow == 3 then -- Can merge
print("CAN MERGE DRAGON", CurrentDragonIndex, slotIndex)
-- Remove dragons 2 and 3
Data.Dragons[slotIndex] = nil
Data.Dragons[slotIndex - 1] = nil
-- Set dragon 1 to increase by 1
Data.Dragons[slotIndex - 2] = CurrentDragonIndex + 1
break
end
end