Help with tables and arrays?!

I still can’t get my head around tables and arrays what’s the difference and how do they work and what do they do.Does anyone have any tutorials I know reefwing made one but I don’t understand it.

Do a forum search for tables or arrays and you’ll find plenty of examples and explanations.

Maybe these will help

https://coolcodea.wordpress.com/2013/04/07/26-tables/

https://coolcodea.wordpress.com/2014/10/01/169-why-tables-and-classes-are-so-useful/

Thanks @Ignatz and @dave1707 I have a question though if I have a Sprite in here like this.

robot = {sprite(…),sprite(…)}

How can I display this because
sprite(robot) doesn’t work.

sprite(robot[1])

Thanks so much @yojimbo2000

I tried it but it doesn’t work.

@majied Try something like this.

function setup()
    robot={"Planet Cute:Character Boy",
            "Planet Cute:Character Cat Girl",
            "Planet Cute:Character Horn Girl"}
end

function draw()
    background(40, 40, 50)
    sprite(robot[1],WIDTH/2,HEIGHT/2)
end

It works when I use it in a separate project but it doesn’t work in my own?

Oh thanks @dave1707 I fixed it it was an unassigned string .
For some reason Codea marks red the line below the incorrect line.

Without seeing any code, we can’t say what’s wrong.

@dave1707 How can I do this so it shows all of the sprites

@majied If you have the sprites in a table, then you need to iterate thru the table to show each Sprite. Without knowing what you’re doing, I can’t tell you more.

@majied Here’s the above code showing how to go thru the table to display each Sprite.

function setup()
    robot={"Planet Cute:Character Boy",
            "Planet Cute:Character Cat Girl",
            "Planet Cute:Character Horn Girl"}
end

function draw()
    background(40, 40, 50)
    for z=1,#robot do
        sprite(robot[z],WIDTH/2,HEIGHT-200*z)
    end
end

Yeah exactly

@majied Try this. Tap the screen where you want a Sprite.

function setup()
    tab={}
end

function draw()
    background(40, 40, 50)
    for a,b in pairs(tab) do
        sprite("Planet Cute:Character Boy",b.x,b.y)
    end
end

function touched(t)
    if t.state==BEGAN then
        table.insert(tab,vec2(t.x,t.y))
    end
end

How Can I make it so that when I touch the screen it creates a Sprite where I touched it I can use table.insert but I can’t save the X and y positions

@dave1707

@majied Do you want a Sprite to show at every x,y position that you touch. Give me more info of what you want to do.

It works but i can’t display it with the z From the code before