Storing Last Clicked Position in a Grid Array

Hi all,

I have a grid built using nested tables in corona.

In my app, when the user taps on an object inside the grid, it changes to another object. That is working fine…

My question is, how to I store a previously tapped item so I can remove it when the current tapped item is selected.

On each grid item, store its column and row value as a parameter. i.e. object.row = 4, object.col = 2.

When it’s tapped, retrieve these values (event.target.row and event.target.col) and store them.

[lua]

– top of lua file

local lastTap = {row = 0, col = 0}  

– within tap listener

lastTap.row = event.target.row

lastTap.col = event.target.col

[/lua]

You can then check the values of lastTap.row and lastTap.col and if they are not zero, use them to remove the item and then reset both values to zero.

On each grid item, store its column and row value as a parameter. i.e. object.row = 4, object.col = 2.

When it’s tapped, retrieve these values (event.target.row and event.target.col) and store them.

[lua]

– top of lua file

local lastTap = {row = 0, col = 0}  

– within tap listener

lastTap.row = event.target.row

lastTap.col = event.target.col

[/lua]

You can then check the values of lastTap.row and lastTap.col and if they are not zero, use them to remove the item and then reset both values to zero.