I had made a topic before about the same error, but this one is different. I measure the amount of lives the player has in game by displaying hearts and counting the lives. But sometimes a get the nil value error on line 365:
local function playerHit() character:setLinearVelocity(0, nil) composer.gotoScene("level1-Try-Again") timer.cancel(firstTimer) timer.cancel(secondTimer) timer.cancel(moveEnemiesTimer) lives[livesCount].alpha = 0 --Line 365 livesCount = livesCount - 1 if(livesCount \< 1) then onGameOver() end end
This is how I create and manage lives:
local lives = {} -- table that will hold the lives object local livesCount = 4 for i=1, livesCount do lives[i] = display.newImageRect("heart.png", 50, 50) lives[i].x = \_L + (i \* 65) - 25 lives[i].y = \_T + 50 end
Sincerely,
Alex

