timer, score, graphics instead of text and switching images problems

Hi all,

I’m working on my first Corona game. It’s a simple point collecting game by pressing on images on the screen. The images will change to another image every 2 seconds on random coordinates (these are pre determined, I used print(event.target.x, event.target.y to get these). 

When an image got pressed it will be removed and spawns a new one in the following second. Every images has it’s own set of properties like points, bonus points, instant game over, etc. 

I can spawn a new image if the previous got pressed on, with a delay of 2 seconds. But now I’m having trouble with the switch image function, game timer, score and display graphics instead of text. 

switchImage: I would like to switch an image to another one, in order to do that it needs to remove the previous one. How can I remove the previous image?

score:  I’m using this score module (http://coronalabs.com/blog/2013/12/10/tutorial-howtosavescores/). It seems I can’t add points from a table. I have looked at http://coronalabs.com/blog/2011/06/21/understanding-lua-tables-in-corona-sdk/ but I can’t see what I have done wrong.

timer: Basically the same problem with the score, not able getting any content from a table. And also how can I set a max value, the timer can’t go above this value.

graphics: How can I display graphics instead of text. If the player has collected x amount of points it displays image x, y points = y image, etc. At first I thought I could use if-statements: if score = x then display image x. But this method would be a lot of copy-pasting. There has to be a better way to do this.

The code I have at this moment is:

local score\_mod = require( "score" )    math.randomseed( os.time() ) local scoreText = score\_mod.init({ fontSize = 70,    font = native.systemFont, x = display.contentCenterX - 100,    y = display.contentCenterY + 170,    filename = "scorefile.txt"    }) scoreText:setTextColor( (232/255), (216/255), (32/255) )   local function Game ()  time = 20 local gameTimer = display.newText(time, 20, 20, native.systemFont, 70) gameTimer.x = display.contentCenterX + 50 gameTimer.y = display.contentCenterY + 170   function countDown() time = time - 1     gameTimer.text = time end timer.performWithDelay(1000, countDown, -1)   local images ={ {name = "Icon.png", points = 1, timePoints = 1}, {name = "Icon-mdpi.png", points = 2, timePoints = 2},    {name = "Icon-xhdpi.png", points = 3, timePoints = 1},    {name = "Icon-ldpi.png", points = 4, timePoints = 1},    {name = "Icon-Small-50.png", points = 5, timePoints = 1} }   local numRows = 3 local numCols = 2   local blockWidth = display.contentCenterX / 2.2 local blockHeight = display.contentCenterY / 2 local row local col   function imagePress (event) if event.phase == "began" then local x = event.target.x     local y = event.target.y      event.target:removeSelf() --time = time + images["timePoints"] --score\_mod.set() = score\_mod.get() + images["points"]       function nextImages(x, y)       local nextImage = display.newImage(images[math.random(1,5)].name, x, y)     nextImage:addEventListener( "touch", imagePress )    end       local nextDelay = function() return nextImages(x, y) end     timer.performWithDelay( 1000, nextDelay, 1 )       end    return true   end   function switchImages (swX, swY) local swX = math.random(2) == 1 and 120 or 192.72727966309 local swY = math.random(3) == 1 and 80 or 200 or 320 --coordinates I got with print(event.target.x, event.target.y) local function preSwitch (pre) pre:removeSelf(swX, swY) end local switchImage = display.newImage(images[math.random(1,5)].name, swX, swY) switchImage:addEventListener(2000, "touch", imagePress ) end   local switchDelay = function() return switchImages(swX, swY) end timer.performWithDelay( 100, delay, -1 )     function makeImage() for row = 1, numRows do   for col = 1, numCols do   local x = (col - 1) \* blockWidth + 120     local y = (row + 1) \* blockHeight - 160   local image = display.newImage(images[math.random(1,5)].name, x, y) image:addEventListener( "touch", imagePress )     end end end makeImage() end Game()