Spawning rectangles

Question about spawning more than 1 rectangle at a time, but not by making hundreds of variables for every single one of them.
This is what I did at first

function setup()
    rectx=400
    recty=100
end
function draw()
    background(40, 40, 50)
    recty=recty+1
    if touched==true then
        rect(rectx,recty,200)
    end
end
function touched(t)
    if t.state==BEGAN then
        touched=true
    end
end

But if you do this, you can only spawn 1 at a time. Some help would be appreciated.

You need a table. If the object begins to get more complex than just a rectangle, then you should create a class.

function setup()
    rects={vec2(400, 100)} --a table to hold the position (stored as a vec2) of each rect
    parameter.watch("#rects") --watch the number of recrs to make sure rect removal is working
end
function draw()
    background(40, 40, 50)
    for i,v in ipairs(rects) do --iterate through each rect. v is short for value, in thus case the vector at each position in the table
        v.y = v.y + 1
        rect(v.x,v.y,200)
        if v.y>HEIGHT then
            table.remove(rects, i) --remove rects once they disappear off screen
        end
    end
end
function touched(t)
    if t.state==BEGAN then
        rects[#rects+1]=vec2(t.x,t.y) --add a new rect at touch point    
    end
end