GDL Space - A Space for GDL code. This is my main script and I would like to switch between my two grids. Is there a way to hijack the selectNextRow(true) function and make it so instead of looping it triggers a Boolean which can then swap the grids? I don't know any other way to switch between two grids if there is a better way that would be great.
Since your code is the one calling both selectNextRow()
and yourGridView:drawInRect()
, you should be able to handle this with logic in your code without hijacking anything.
If you want to trigger the swap action when the current grid view is on the last row, you could do something like this to test for the condition:
function moveToNextRow()
-- assuming only one section, and that you are calling currentGridView: drawInRect() to draw your grid view
local _, selectedRow, _ = currentGridView:getSelection()
local lastRow = currentGridView:getNumberOfRowsInSection(1)
if selectedRow < lastRow then
selectNextRow()
else
currentGridView = newGridView -- where "newGridVew" is the gridView you want to swap to
end
end
OR, you can also view the gridview source code (or copy it out to your project and modify it to better suit your needs!) in your SDK folder in CoreLibs/ui/gridview.lua
.
As a side note, you probably don't want this code
upgradeGridView:setNumberOfRows(4)
upgradeGridView:setNumberOfColumns(4)
upgradeGridView:setCellPadding(1, 1, 1, 1)
to be inside your main playdate.update()
function, as that will cause it to be called every frame. Instead you can just set these values up once after you create your gridview instance.
Thank you so much this solution works I was really overcomplicating it.