Corona Grid with ID for each element

Hi. I’m a newbie to Corona and the Lua Programming Language.

I’m creating a grid based application, a feature of which, displays a grid of images.

I want to assign a unique numeral id for each image in the grid by assigning each element a property, e.g. myImage.ID = counter

I know I need a counter but I cannot seem how to do this. I can get it to display a count for the rows or columns but not each cell.

Its probably something simple but I cannot seem to figure it out.

Any help would be greatly appreciated.

&nbsp;&nbsp;&nbsp; local chipWidth = 150 &nbsp;&nbsp;&nbsp; local chipHeight = 150 &nbsp;&nbsp;&nbsp; local colSpace = 0 &nbsp;&nbsp;&nbsp; local rowSpace = 0 &nbsp;&nbsp;&nbsp; local numCols = 25 &nbsp;&nbsp;&nbsp; local numRows = 25 &nbsp;&nbsp;&nbsp; gd = {} --table &nbsp;&nbsp;&nbsp; for col = 1, numCols do &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;gd[col] = {} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for row = 1, numRows do &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local chip = display.newImageRect("grassIco.png", chipWidth, chipHeight) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chip.x = col \* chip.width - chip.width/2 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chip.y = row \* chip.height - chip.height/2 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chip.gridPos = {x=col, y=row} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chip.isSelected = false &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chip.state = "grass" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chip.id = "" --\<\<\<\< Need to populate a UNIQUE ID HERE using a counter value. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chip:addEventListener("tap", chipTapped) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gd[col][row] = chip &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local myText = display.newText(row, chip.x, chip.y, native.systemFontBold, 36) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; group:insert(chip) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; group:insert(myText) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp; end

Sorted This Issue…

same problem.

Here was my solution to this.

 local chipWidth = 150 local chipHeight = 150 local colSpace = 0 local rowSpace = 0 local counter = 0 gd = {} --table for col = 1, numCols do gd[col] = {} for row = 1, numRows do local grass = display.newImageRect("grassIco.png", chipWidth, chipHeight) grass.x = col \* grass.width - grass.width/2 grass.y = row \* grass.height - grass.height/2 grass.gridPos = {x=col, y=row} grass.isSelected = false grass.state = "Grass" grass:addEventListener("tap", chipTapped) gd[col][row] = grass counter = counter + 1 local myText = display.newText(counter, grass.x, grass.y, native.systemFontBold, 36) grass.id = counter group:insert(grass) group:insert(myText) end end

Sorted This Issue…

same problem.

Here was my solution to this.

 local chipWidth = 150 local chipHeight = 150 local colSpace = 0 local rowSpace = 0 local counter = 0 gd = {} --table for col = 1, numCols do gd[col] = {} for row = 1, numRows do local grass = display.newImageRect("grassIco.png", chipWidth, chipHeight) grass.x = col \* grass.width - grass.width/2 grass.y = row \* grass.height - grass.height/2 grass.gridPos = {x=col, y=row} grass.isSelected = false grass.state = "Grass" grass:addEventListener("tap", chipTapped) gd[col][row] = grass counter = counter + 1 local myText = display.newText(counter, grass.x, grass.y, native.systemFontBold, 36) grass.id = counter group:insert(grass) group:insert(myText) end end