Thanks!
I just tried your code, took some tiny tiny tiny errors out of it and now it works like a charm.
Here’s my adapted code, for detecting groups of 3 blocks (yep, I went from 4 to 3) in a horizontal row or vertical column:
-- set a random game board each number stands different color block
gameData = {}
for a = 1, 30 do
gameData[a] = math.random(5)
end
for y = 0,5 do
print(gameData[1+y\*5].." "..gameData[2+y\*5].." "..gameData[3+y\*5].." "..gameData[4+y\*5].." "..gameData[5+y\*5])
end
print("---------")
function fnCheckBlocks()
popTable = {}
for ct = 1, 30 do
if (ct-1)%5 \< 3 then -- no need to check pass 3rd column for row match
if (gameData[ct] == gameData[ct+1]) and (gameData[ct] == gameData[ct+2]) then
pop1 = { 0, 1, 2}
for a = 1, 3 do
table.insert( popTable, #popTable+1, ct+pop1[a] )
end
end
end
if (ct \< 21) then --no need to check pass 4th row for column match
if (gameData[ct] == gameData[ct+5]) and (gameData[ct] == gameData[ct+10]) then
pop2 = { 0, 5, 10}
for a = 1, 3 do
table.insert( popTable, #popTable+1, ct+pop2[a] )
end
end
end
end
--sort table
table.sort(popTable)
---unique table, removes double entries from table
local newTable = {}
local lastNumber = 0
for ct = 1, #popTable do
nextNumber = popTable[ct]
if (nextNumber ~= lastNumber) then
newTable[#newTable+1] = nextNumber
end
lastNumber = nextNumber
end
-- build Array with 1s where blocks match
local popGrid = {}
for i = 1, 30 do
popGrid[i] = 0
end
for i = 1, #newTable do
popGrid[newTable[i]] = 1
end
for y = 0,5 do
print(popGrid[1+y\*5].." "..popGrid[2+y\*5].." "..popGrid[3+y\*5].." "..popGrid[4+y\*5].." "..popGrid[5+y\*5])
end
print("---------")
end
fnCheckBlocks()
By the way, the biggest (little) bug in your code was in the line:
if (ct-1)%5 \< 3 then -- no need to check pass 3rd column for row match
You said ‘if ct%5 < 3’ but it needs to be ‘if (ct-1)%5 < 3’, or your detection ‘wraps around’ the grid - for lack of better words!
Thanks again - this is a wonderful forum 
Thomas
[import]uid: 70134 topic_id: 14746 reply_id: 54736[/import]