In the Corona Labs forum someone was wanting to add an extra life every time the player gained another 5,000 points.
One way to add a new life every so many points is just keep track of the score and also a “life counter” like this
local currentScore = 0 local lifeCounter = 0 local function addToScore(num) currentScore = currentScore + num lifeCounter = lifeCounter + num if lifeCounter >= 5000 then lifeCounter = 0 addLives() -- bonus or whatever called here end end
When the player kills an enemy or does something else to gain a core, just call the function and pass in however many points to add:
That will add 500 points to the score and every time you add to the score, you also add to the lifeCounter variable. When that hits 5K, reset it to zero and add a new life or do whatever bonus action you want there.
In fact, what you do could be considered a negative — maybe another enemy ship is spawned every 1,000 points, etc. You can do that using the technique shown.
Edit: primoz.cerar on Corona Labs forum tweaked one of the lines which makes the code snippet better. Instead of:
lifeCounter = 0
…inside the if block, do this:
lifeCounter = lifeCounter - 5000
That way you’re more accurately doing something every 5,000 points.