Help with creating lives

-- Rocket Run

displayMode(FULLSCREEN)

function setup() 
    lives=3
    w=WIDTH/2 
    h=HEIGHT/2
    instr=true
    boxTab={}
    for z=1,10 do
        table.insert(boxTab,vec3(math.random(WIDTH,WIDTH+100),
                        math.random(50,HEIGHT-50),
                        math.random(4,10)))        
    end
end

function draw()
    background(255, 255, 255, 255)
    strokeWidth(5)
    lives = lives - 1
    if instr then
        instructions()
    else
        sprite("SpaceCute:Background",w,h,WIDTH,HEIGHT)
        sprite("SpaceCute:Rocketship",spx,spy,200) 
        showBoxes()
        checkHit()
    end
end 
function touched(touch)
    instr=false
    spx = touch.x+10
    spy = touch.y
end 

function showBoxes()
    for a,b in pairs(boxTab) do
        sprite("Space Art:Asteroid Small",b.x,b.y)
        b.x=b.x-b.z
            if b.x<0 then
            b.x=math.random(WIDTH,WIDTH+100)
            b.y=math.random(50,HEIGHT-50) 
            b.z=math.random(4,10)     
        end
    end
end  

function checkHit()
    for a,b in pairs(boxTab) do
        v1=vec2(spx,spy)
        if v1:dist(vec2(b.x,b.y))<75 then
            sprite("Tyrian Remastered:Explosion Huge",b.x,b.y)
            table.remove(boxTab,a)
        end
    end
end
        
function instructions() 
    fill(224, 149, 129, 255) 
    fontSize(25) 
    text("This is a game made by Andrew Brown",w,650) 
    text("You have to dodge the asteroids",w,600) 
    fontSize(20)
    text("Tap the screen to start.",w,500)
end

--

I need help i am somewhat a beginner at coding and I have had help from some people but I need help on how to make lives. Thanks

@abrown18 Please format your code with three of these ~ at the begging and end like this

-- Rocket Run

displayMode(FULLSCREEN)

function setup() lives=3 w=WIDTH/2 h=HEIGHT/2 instr=true boxTab={} for z=1,10 do table.insert(boxTab,vec3(math.random(WIDTH,WIDTH+100), math.random(50,HEIGHT-50), math.random(4,10)))
end end

function draw() background(255, 255, 255, 255) strokeWidth(5) lives = lives - 1 if instr then instructions() else sprite("SpaceCute:Background",w,h,WIDTH,HEIGHT) sprite("SpaceCute:Rocketship",spx,spy,200) showBoxes() checkHit() end end function touched(touch) instr=false spx = touch.x+10 spy = touch.y end

function showBoxes() for a,b in pairs(boxTab) do sprite("Space Art:Asteroid Small",b.x,b.y) b.x=b.x-b.z if b.x<0 then b.x=math.random(WIDTH,WIDTH+100) b.y=math.random(50,HEIGHT-50) b.z=math.random(4,10)
end end end

function checkHit() for a,b in pairs(boxTab) do v1=vec2(spx,spy) if v1:dist(vec2(b.x,b.y))<75 then sprite("Tyrian Remastered:Explosion Huge",b.x,b.y) table.remove(boxTab,a) end end end

function instructions() fill(224, 149, 129, 255) fontSize(25) text("This is a game made by Andrew Brown",w,650) text("You have to dodge the asteroids",w,600) fontSize(20) text("Tap the screen to start.",w,500) end

Please use three (~) before and after your code to format it, I edited your original post to include this. To make lives just create a variable to hold the number of lives. example: lives = 3 then just subtract or add when needed. then use an if statment to check if lives == 0

@Prynok I seem to be a few seconds behind you!

@abrown18 See the code I added.


-- Rocket Run

displayMode(FULLSCREEN)

function setup() 
    lives=3
    w=WIDTH/2 
    h=HEIGHT/2 
    instr=true 
    boxTab={} 
    for z=1,10 do 
        table.insert(boxTab,vec3(math.random(WIDTH,WIDTH+100), 
            math.random(50,HEIGHT-    50), math.random(4,10)))
    end 
end

function draw() 
    background(255, 255, 255, 255) 
    strokeWidth(5) 
    if instr then 
        instructions() 
    else 
        sprite("SpaceCute:Background",w,h,WIDTH,HEIGHT)        
        sprite("SpaceCute:Rocketship",spx,spy,200) 
        showBoxes() 
        checkHit()
        text("Lives  "..lives,WIDTH/2,HEIGHT-50)    -- added
    end 
end 

function touched(touch) 
    if touch.state==BEGAN then   -- added
        instr=false 
    end -- added
    spx = touch.x+10 
    spy = touch.y 

end

function showBoxes() 
    for a,b in pairs(boxTab) do 
        sprite("Space Art:Asteroid Small",b.x,b.y) 
        b.x=b.x-b.z 
        if b.x<0 then 
            b.x=math.random(WIDTH,WIDTH+100) 
            b.y=math.random(50,HEIGHT-50) 
            b.z=math.random(4,10)
        end 
    end 
end

function checkHit() 
    for a,b in pairs(boxTab) do 
        v1=vec2(spx,spy) 
        if v1:dist(vec2(b.x,b.y))<75 then 
            sprite("Tyrian Remastered:Explosion Huge",b.x,b.y) 
            table.remove(boxTab,a) 
            lives=lives-1    -- added
        end 
    end 
    if lives<1 then    -- added
        setup()    -- added
    end  -- added
end

function instructions() 
    fill(224, 149, 129, 255) 
    fontSize(25) text("This is a game made by Andrew Brown",w,650) 
    text("You have to dodge the asteroids",w,600) 
    fontSize(20) 
    text("Tap the screen to start.",w,500) 
end

Just wondering, how could you write a game with tables, but not know how to add lives? If this is based off another game, please give credit

@CodeaNoob To each their own, I guess.