Make function create 1 object from a table followed by 2 and so on..

I am stuck trying to get my function to load a single object from within a pre set table. for example, I have objects 1,2,3 inside a table and the function will display 1 of those complete with its parameters. Then it will pick 2 from a much larger table of objects.

In my current set up my function just creates every object from the table and places them on top of each other. 

Can someone help me as to how to properly do this? 

Cheers

Table

local Shapes = {"Triangle", "Square", "Circle"}

Spawning shapes

function spawnShape() shuffleArray(Shapes) for i = 1, #Shapes do local shapeName = Shapes[i] local posX = \_W/2 -- display.contentWidht / 2 local posY = \_H/2 - 100 if shapeName == "Triangle" then Shape = display.newImageRect("Shapes/triangleBlue.png", 35,35) Shape.name = "triangle" physics.addBody(Shape, {isSensor=true}) Shape.x = posX Shape:toFront() Shape.y = posY Shape.alpha = 0 Shape.xScale = 0.1 Shape.yScale = 0.1 --soundDelay = timer.performWithDelay(sfxDelay, playPop1) elseif shapeName == "Square" then Shape = display.newImageRect("Shapes/squareRed.png", 33,33) Shape.name = "square" physics.addBody(Shape, {isSensor=true}) Shape.x = posX Shape:toFront() Shape.y = posY Shape.alpha = 0 Shape.xScale = 0.1 Shape.yScale = 0.1 --enemyMovement2 = transition.to( red, { time=1000, alpha=1} ) else --create green enemy Shape = display.newImageRect("Shapes/circleGreen.png", 35,35) Shape.name = "circle" physics.addBody(Shape, {isSensor=true}) Shape.x = posX Shape:toFront() Shape.y = posY Shape.alpha = 0 Shape.xScale = 0.1 Shape.yScale = 0.1 end end end

[lua]

local Shapes = {

{name = “Triangle”, fileName = “triangleBlue.png”, size = 35 },

{name = “Square”, fileName = “squareRed.png”, size = 33 },

{name = “Circle”, fileName = “circleGreen.png”, size = 35 }

}

function spawnShape()

            shuffleArray(Shapes)

            local shapeUse = Shapes[1]

        local posX = _W/ 2 – display.contentWidht / 2

        local posY = _H/ 2 - 100

       

  local Shape = display.newImageRect(“Shapes/” …s hapeUse.fileName,  shapeUse.size, shapeUse.size)

            Shape.name = shapeUse.name

        physics.addBody(Shape, {isSensor=true})

        Shape.x = posX

        Shape:toFront()

        Shape.y = posY

        Shape.alpha = 0

        Shape.xScale = 0.1

         Shape.yScale = 0.1

        

       

    

  

end

spawnShape()

[/lua]

Thats great, thanks for that. It works as I wanted 

[lua]

local Shapes = {

{name = “Triangle”, fileName = “triangleBlue.png”, size = 35 },

{name = “Square”, fileName = “squareRed.png”, size = 33 },

{name = “Circle”, fileName = “circleGreen.png”, size = 35 }

}

function spawnShape()

            shuffleArray(Shapes)

            local shapeUse = Shapes[1]

        local posX = _W/ 2 – display.contentWidht / 2

        local posY = _H/ 2 - 100

       

  local Shape = display.newImageRect(“Shapes/” …s hapeUse.fileName,  shapeUse.size, shapeUse.size)

            Shape.name = shapeUse.name

        physics.addBody(Shape, {isSensor=true})

        Shape.x = posX

        Shape:toFront()

        Shape.y = posY

        Shape.alpha = 0

        Shape.xScale = 0.1

         Shape.yScale = 0.1

        

       

    

  

end

spawnShape()

[/lua]

Thats great, thanks for that. It works as I wanted