Help with tables and arrays?!

Can you merge them into one script because i don’t know how to do this

@majied The value of z was determining which Sprite from the table you were going to display. The other code was just displaying a Sprite at the x,y position you touched. How do you want to control which Sprite from the table you want to display.

Here’s an example of incrementing the robot table position each time the screen is touched.

displayMode(FULLSCREEN)

function setup()
    z=1
    tab={}
    robot={"Planet Cute:Character Boy",
            "Planet Cute:Character Cat Girl",
            "Planet Cute:Character Horn Girl",
            "Planet Cute:Character Pink Girl",
            "Planet Cute:Character Princess Girl"}
end

function draw()
    background(40, 40, 50)
    for a,b in pairs(tab) do
        sprite(robot[b.z],b.x,b.y)
    end
end

function touched(t)
    if t.state==BEGAN then
        table.insert(tab,vec3(t.x,t.y,z))
        z=z+1
        if z>#robot then
            z=1
        end
    end
end

It works in a seperate project but not this one. Is there any problems?

function setup()
    tbs = 0
    tboc= "Hover Cursor Over Bar To Open The Toolbox."
    selectedmaterial = 1
    tab={}
    robot={"Planet Cute:Character Boy",
            "Planet Cute:Character Cat Girl",
            "Planet Cute:Character Horn Girl",
            "Planet Cute:Character Pink Girl",
            "Planet Cute:Character Princess Girl"}
    recources = {"Wood","Metal","Tyre","Mounted Gun","Grenade Launcher","Blade"}
    activeblock =  {"Documents:wood","Documents:Metal","Documents:tyre","Documents:gun","Documents:launcher","Documents:chainsaw"}
    blocksused = 0
    mx = WIDTH/2
    my = HEIGHT/2
    recourtexttransparent = 150
    z = 1
end

function draw()
    if selectedmaterial > 6 then
        selectedmaterial = 1
    end
    mx = CurrentTouch.x
    my = CurrentTouch.y
    background(255, 255, 255, 255)
    fill(0, 169, 255, 255)
    rect(-10,710,1100,100)
    font("GillSans")
    fill(0, 0, 0, 255)
    text(tboc,WIDTH/2,726)
    fill(0, 0, 0,recourtexttransparent)
    font("HelveticaNeue-CondensedBold")
    text(recources[selectedmaterial],WIDTH/2,100)
    fill(0, 0, 0, 255)
    textSize(100)
    sprite("Documents:Undo",30,30,50,50)
    if tbs == 1 then
        sprite("Cargo Bot:Toolbox",130,600)
        sprite(activeblock[selectedmaterial],130,600)
        sprite("Documents:next",130,480,80,60)
    end
    if CurrentTouch.y > 710 then
        tbs = 1
        tboc = "Shake left to right to close Toolbox."
    end
    if UserAcceleration.x > 1 then
        tbs = 0
        tboc = "Hover Cursor Over Bar To Open The Toolbox."
        selectedmaterial = 1
    end
     for a,b in pairs(tab) do
        sprite(robot[b.z],b.x,b.y)
    end
    sprite("Documents:Cursor",mx,my,20,30)
    if recourtexttransparent > 0 then
        recourtexttransparent = recourtexttransparent - 1
    end
end
function touched(t)
    -- Undo
    if CurrentTouch.state == ENDED then
        if CurrentTouch.x < 50 and CurrentTouch.y < 50 then
            if blocksused > 0 then
                blocksused = blocksused - 1
                print("Undo")
                table.remove(robot,j)
            else
                print("Can not undo")
        end
    end
    -- Next Object
        if CurrentTouch.y > 450 and CurrentTouch.y < 510 and CurrentTouch.x > 90 and CurrentTouch.x < 170 then
            selectedmaterial = selectedmaterial + 1
            recourtexttransparent = 255
        end
        -- Place Object
     if t.state==BEGAN then
        table.insert(tab,vec3(t.x,t.y,z))
        z=z+1
        if z>#robot then
            z=1
        end
    end
end
end

@majied Check your touched function. The end statements aren’t matched up with the if statements. Everything is in the ENDED if statement, so the BEGAN if statement will never execute.

Oh thank you ! :smiley: