How to move one row of a grid?
Posted: Mon Jul 08, 2019 4:46 pm
I have every cell of a grid in a table. How would I go about shifting all the cells over and moving the last row to the first row?
Code: Select all
local grid = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
}
local numColumns = 3
local numRows = 3
for column = 1, numColumns do
local wrappedElement = grid[numRows][column]
for row = numRows, 2, -1 do
grid[row][column] = grid[row - 1][column]
end
grid[1][column] = wrappedElement
end
for i = 1, numRows do print(unpack(grid[i])) end
--[[
output:
7 8 9
1 2 3
4 5 6
--]]