Thanks to everyone for your ideas and suggestions, I ended up finding a method that works well for my case. (although it took me a whole day to conjure…)
Here’s a portion of the script I wrote that demonstrates the basics of this method:
--This table of arrays is a visual representation of the tetris game board in the code logic.
local board = {
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0}
}
--Rotations always turn counter-clockwise from the top!
local tetros = {
--'I' Tetromino
{
{--Rot1
{1,1,1,1},
},
{--Rot2
{1},
{1},
{1},
{1}
},
{--Rot3
{1,1,1,1},
},
{--Rot4
{1},
{1},
{1},
{1}
}
},
--'L' Tetromino
{
{--Rot1
{2,0,0},
{2,2,2},
{0,0,0}
},
{--Rot2
{0,2,0},
{0,2,0},
{2,2,0}
},
{--Rot3
{0,0,0},
{2,2,2},
{0,0,2}
},
{--Rot4
{0,2,2},
{0,2,0},
{0,2,0}
}
},
--'J' Tetromino
{
{--Rot1
{0,0,3},
{3,3,3},
{0,0,0}
},
{--Rot2
{3,3,0},
{0,3,0},
{0,3,0}
},
{--Rot3
{0,0,0},
{3,3,3},
{3,0,0}
},
{--Rot4
{0,3,0},
{0,3,0},
{0,3,3}
}
},
--'O' Tetromino
{
{--Rot1
{4,4},
{4,4}
},
{--Rot2
{4,4},
{4,4}
},
{--Rot3
{4,4},
{4,4}
},
{--Rot4
{4,4},
{4,4}
}
},
--'S' Tetromino
{
{--Rot1
{0,5,5},
{5,5,0},
{0,0,0}
},
{--Rot2
{5,0,0},
{5,5,0},
{0,5,0}
},
{--Rot3
{0,5,5},
{5,5,0},
{0,0,0}
},
{--Rot4
{5,0,0},
{5,5,0},
{0,5,0}
}
},
--'Z' Tetromino
{
{--Rot1
{6,6,0},
{0,6,6},
{0,0,0}
},
{--Rot2
{0,6,0},
{6,6,0},
{6,0,0}
},
{--Rot3
{6,6,0},
{0,6,6},
{0,0,0}
},
{--Rot4
{0,6,0},
{6,6,0},
{6,0,0}
}
},
--'T' Tetromino
{
{--Rot1
{0,7,0},
{7,7,7},
{0,0,0}
},
{--Rot2
{0,7,0},
{7,7,0},
{0,7,0}
},
{--Rot3
{0,0,0},
{7,7,7},
{0,7,0}
},
{--Rot4
{0,7,0},
{0,7,7},
{0,7,0}
}
},
}
local tetro = {
0;--Tetromino value from table:tetros
0;--Rotation value of tetromino
0;--Y position of tetromino
0;--X position of tetromino
}
local nextTetro
local function SpawnTetro()
for i,v in pairs(tetro[2]) do--Draws tetromino on table
local line = board[i]
local offset = 0
for ii,vv in pairs(v) do
if vv ~= 0 then line[tetro[4]+offset] = vv end
offset += 1
end
end
end
local function DefineTetro()
if nextTetro ~= nil then
tetro[1] = tetros[nextTetro]--Defines the new tetromino
else
tetro[1] = tetros[math.random(1, #tetros)]--Defines the new tetromino
end
tetro[2] = (tetro[1])[1]--Defines the rotation (DEFAULT 1)
tetro[3] = 1--Defines the Y position
tetro[4] = 4--Defines the X position
print("Defined current tetromino.")
nextTetro = tetros[math.random(1, #tetros)]--Defines the next tetromino
print("Defined next tetromino.")
end
Again, thank you to everyone who replied!